回答編集履歴
12
修正
answer
CHANGED
@@ -17,6 +17,13 @@
|
|
17
17
|
{
|
18
18
|
int i = r.Next(11);
|
19
19
|
|
20
|
+
Console.WriteLine($"0~10の値を出力:{i}");
|
21
|
+
|
22
|
+
if (i == 0)
|
23
|
+
{
|
24
|
+
break;
|
25
|
+
}
|
26
|
+
|
20
27
|
if (i % 2 == 0)
|
21
28
|
{
|
22
29
|
even.Add(i);
|
@@ -25,13 +32,6 @@
|
|
25
32
|
{
|
26
33
|
odd.Add(i);
|
27
34
|
}
|
28
|
-
|
29
|
-
Console.WriteLine($"0~10の値を出力:{i}");
|
30
|
-
|
31
|
-
if (i == 0)
|
32
|
-
{
|
33
|
-
break;
|
34
|
-
}
|
35
35
|
}
|
36
36
|
|
37
37
|
string answer(List<int> data)
|
@@ -85,4 +85,6 @@
|
|
85
85
|
}
|
86
86
|
}
|
87
87
|
}
|
88
|
-
```
|
88
|
+
```
|
89
|
+
#補足
|
90
|
+
hidori様にご指摘いただいた箇所を修正しました。
|
11
修正
answer
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
if (i < data.Count - 1)
|
46
46
|
{
|
47
|
-
ans +=
|
47
|
+
ans += ' ';
|
48
48
|
}
|
49
49
|
}
|
50
50
|
|
10
修正
answer
CHANGED
@@ -60,8 +60,18 @@
|
|
60
60
|
}
|
61
61
|
```
|
62
62
|
考えてみました。
|
63
|
-
文字列をスペースで分割してリストにする場合
|
63
|
+
文字列をスペースで分割してリストにする場合。
|
64
64
|
```C#
|
65
|
+
using System;
|
66
|
+
using System.Linq;
|
67
|
+
using System.Collections.Generic;
|
68
|
+
|
69
|
+
namespace randomtest1
|
70
|
+
{
|
71
|
+
class Program
|
72
|
+
{
|
73
|
+
static void Main(string[] args)
|
74
|
+
{
|
65
75
|
string str = "a b c";
|
66
76
|
|
67
77
|
List<string> list = str.Split(' ').ToList();
|
@@ -70,4 +80,9 @@
|
|
70
80
|
{
|
71
81
|
Console.WriteLine(s);
|
72
82
|
}
|
83
|
+
|
84
|
+
Console.ReadKey();
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
73
88
|
```
|
9
修正
answer
CHANGED
@@ -59,4 +59,15 @@
|
|
59
59
|
}
|
60
60
|
}
|
61
61
|
```
|
62
|
-
考えてみました。
|
62
|
+
考えてみました。
|
63
|
+
文字列をスペースで分割してリストにする場合
|
64
|
+
```C#
|
65
|
+
string str = "a b c";
|
66
|
+
|
67
|
+
List<string> list = str.Split(' ').ToList();
|
68
|
+
|
69
|
+
foreach(string s in list)
|
70
|
+
{
|
71
|
+
Console.WriteLine(s);
|
72
|
+
}
|
73
|
+
```
|
8
修正
answer
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
while (true)
|
17
17
|
{
|
18
|
-
int i = r.Next(
|
18
|
+
int i = r.Next(11);
|
19
19
|
|
20
20
|
if (i % 2 == 0)
|
21
21
|
{
|
7
修正
answer
CHANGED
@@ -10,8 +10,8 @@
|
|
10
10
|
{
|
11
11
|
Random r = new Random();
|
12
12
|
|
13
|
+
List<int> even = new List<int>();
|
13
14
|
List<int> odd = new List<int>();
|
14
|
-
List<int> even = new List<int>();
|
15
15
|
|
16
16
|
while (true)
|
17
17
|
{
|
6
修正
answer
CHANGED
@@ -10,27 +10,13 @@
|
|
10
10
|
{
|
11
11
|
Random r = new Random();
|
12
12
|
|
13
|
+
List<int> odd = new List<int>();
|
13
|
-
List<int>
|
14
|
+
List<int> even = new List<int>();
|
14
15
|
|
15
16
|
while (true)
|
16
17
|
{
|
17
18
|
int i = r.Next(10);
|
18
19
|
|
19
|
-
list.Add(i);
|
20
|
-
|
21
|
-
Console.WriteLine($"0~10の値を出力:{i}");
|
22
|
-
|
23
|
-
if (i == 0)
|
24
|
-
{
|
25
|
-
break;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
List<int> odd = new List<int>();
|
30
|
-
List<int> even = new List<int>();
|
31
|
-
|
32
|
-
foreach (int i in list)
|
33
|
-
{
|
34
20
|
if (i % 2 == 0)
|
35
21
|
{
|
36
22
|
even.Add(i);
|
@@ -39,6 +25,13 @@
|
|
39
25
|
{
|
40
26
|
odd.Add(i);
|
41
27
|
}
|
28
|
+
|
29
|
+
Console.WriteLine($"0~10の値を出力:{i}");
|
30
|
+
|
31
|
+
if (i == 0)
|
32
|
+
{
|
33
|
+
break;
|
34
|
+
}
|
42
35
|
}
|
43
36
|
|
44
37
|
string answer(List<int> data)
|
@@ -65,6 +58,5 @@
|
|
65
58
|
}
|
66
59
|
}
|
67
60
|
}
|
68
|
-
|
69
61
|
```
|
70
62
|
考えてみました。
|
5
修正
answer
CHANGED
@@ -9,7 +9,9 @@
|
|
9
9
|
static void Main(string[] args)
|
10
10
|
{
|
11
11
|
Random r = new Random();
|
12
|
+
|
12
13
|
List<int> list = new List<int>();
|
14
|
+
|
13
15
|
while (true)
|
14
16
|
{
|
15
17
|
int i = r.Next(10);
|
4
修正
answer
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
list.Add(i);
|
18
18
|
|
19
|
-
Console.WriteLine(i);
|
19
|
+
Console.WriteLine($"0~10の値を出力:{i}");
|
20
20
|
|
21
21
|
if (i == 0)
|
22
22
|
{
|
@@ -63,5 +63,6 @@
|
|
63
63
|
}
|
64
64
|
}
|
65
65
|
}
|
66
|
+
|
66
67
|
```
|
67
68
|
考えてみました。
|
3
修正
answer
CHANGED
@@ -64,3 +64,4 @@
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
```
|
67
|
+
考えてみました。
|
2
修正
answer
CHANGED
@@ -9,9 +9,7 @@
|
|
9
9
|
static void Main(string[] args)
|
10
10
|
{
|
11
11
|
Random r = new Random();
|
12
|
-
|
13
12
|
List<int> list = new List<int>();
|
14
|
-
|
15
13
|
while (true)
|
16
14
|
{
|
17
15
|
int i = r.Next(10);
|
@@ -41,36 +39,28 @@
|
|
41
39
|
}
|
42
40
|
}
|
43
41
|
|
44
|
-
string even_answer = string.Empty;
|
45
|
-
string
|
42
|
+
string answer(List<int> data)
|
46
|
-
|
47
|
-
for (int i = 0; i < even.Count; i++)
|
48
43
|
{
|
49
|
-
|
44
|
+
string ans = string.Empty;
|
50
45
|
|
51
|
-
|
46
|
+
for (int i = 0; i < data.Count; i++)
|
52
47
|
{
|
48
|
+
ans += data[i];
|
49
|
+
|
50
|
+
if (i < data.Count - 1)
|
51
|
+
{
|
53
|
-
|
52
|
+
ans += ",";
|
53
|
+
}
|
54
54
|
}
|
55
|
-
}
|
56
55
|
|
57
|
-
for (int i = 0; i < odd.Count; i++)
|
58
|
-
{
|
59
|
-
|
56
|
+
return ans;
|
60
|
-
|
61
|
-
if (i < odd.Count - 1)
|
62
|
-
{
|
63
|
-
odd_answer += ",";
|
64
|
-
}
|
65
57
|
}
|
66
58
|
|
67
|
-
Console.WriteLine($"偶数:{
|
59
|
+
Console.WriteLine($"偶数:{answer(even)}");
|
68
|
-
Console.WriteLine($"奇数:{
|
60
|
+
Console.WriteLine($"奇数:{answer(odd)}");
|
69
61
|
|
70
62
|
Console.ReadKey();
|
71
63
|
}
|
72
64
|
}
|
73
65
|
}
|
74
|
-
|
75
66
|
```
|
76
|
-
考えてみました。
|
1
修正
answer
CHANGED
@@ -33,7 +33,6 @@
|
|
33
33
|
{
|
34
34
|
if (i % 2 == 0)
|
35
35
|
{
|
36
|
-
Console.WriteLine(i);
|
37
36
|
even.Add(i);
|
38
37
|
}
|
39
38
|
else
|