남영운 :: 남영운

'전체 글'에 해당되는 글 91건

  1. 2020.03.30 C# 백준 14681번 문제 (20.03.30)
  2. 2019.11.26 델리게이트 능동적 싸움인거 같지만 일방적 폭행
  3. 2019.10.25 C# 2048 만들기(19.10.25)
  4. 2019.10.23 2를 왼쪽 끝으로 갔다가 밑에 쭈욱 내리다가 지그재그로 원상복귀시키기(19.10.23)
  5. 2019.10.22 C# 백준 1773번 문제 (19.10.22)
  6. 2019.10.21 C# 백준 2167 문제(19.10.21)
  7. 2019.10.18 C# 백준 10818 최솟값 최댓값
  8. 2019.10.18 C# 백준 2562 문제 최댓값

C# 백준 14681번 문제 (20.03.30)

Console(콘솔)/알고리즘 2020. 3. 30. 15:12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
 
namespace BackJoon
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());
            int n = 0;
            if(x >= -1000 && x <= 1000&& x != 0&&y!= 0&& y >= -1000 && y <= 1000)
            {
                if(x > 0 && y> 0)
                {
                    n = 1;
                }
                else if(x < 0 && y > 0)
                {
                    n = 2;
                }
                else if(x < 0 && y< 0)
                {
                    n = 3;
                }
                else
                {
                    n = 4;
                }
                Console.WriteLine(n);
            }
        }
    }
}
 
 
 

 

 

https://www.acmicpc.net/problem/14681

:

델리게이트 능동적 싸움인거 같지만 일방적 폭행

Console(콘솔)/실습 2019. 11. 26. 17:42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Syntax01
{
    public class App
    {
        Hero hero;
        Monster monster;
        Action<int> action;
        delegate void Del(int a);
        public App()
        {
            this.hero = new Hero();
            this.monster = new Monster();
            this.action = HeroAttackMonster;
            this.hero.Attack(this.monster, this.action);
        }
        private void HeroAttackMonster(int monsterHp)
        {
            if (monsterHp > 0)
            {
                this.hero.Attack(this.monster, this.action);
            }
            else
            {
                this.monster.DieMonster((hp)=> {
                    Console.WriteLine($"몬스터의 체력이 {hp} 이 죽었습니다.");
                });
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace Syntax01
{
    public class Hero
    {
        public Hero()
        {
 
        }
        public void Attack(Monster monster,Action<int> attackComplete)
        {
            //몬스터 체력 감소시킨다.
            monster.hp -= 20;
 
                Console.WriteLine($"HP : {monster.hp}");
 
                Thread.Sleep(200);
            attackComplete(monster.hp);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax01
{
    public class Monster
    {
        public int hp = 100;
        public Monster()
        {
        }
 
        public void DieMonster(Action<int> action)
        {
            action(hp);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
:

C# 2048 만들기(19.10.25)

Console(콘솔)/실습 2019. 10. 25. 16:25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
using System;
 
namespace _2048
{
    public class App
    {
        int[,] arr = new int[44];
        Random random = new Random();
        int count = 0;
        public App()
        {
            int row = random.Next(04);
            int col = random.Next(04);
            arr[row, col] = GetTwoOrFour();
            while (true)
            {
                int row1 = random.Next(04);
                int col1 = random.Next(04);
                if (row != row1)
                {
                    arr[row1, col1] = GetTwoOrFour();
                    break;
                }
            }
            Scan();
            Console.WriteLine();
 
            while (true)
            {
                ConsoleKeyInfo key;
                key = Console.ReadKey(true);
                switch (key.Key)
                {
                    case ConsoleKey.UpArrow:
 
                        moveUp();
                        while (true)
                        {
                            row = random.Next(04);
                            col = random.Next(04);
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = GetTwoOrFour();
                                break;
                            }
                        }
                        Console.WriteLine();
                        Scan();
                        break;
 
                    case ConsoleKey.DownArrow:
 
                        MoveDown();
                        while (true)
                        {
                            row = random.Next(04);
                            col = random.Next(04);
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = GetTwoOrFour();
                                break;
                            }
                        }
                        Console.WriteLine();
                        Scan();
                        break;
                    case ConsoleKey.LeftArrow:
                        MoveLeft();
                        while (true)
                        {
                            row = random.Next(04);
                            col = random.Next(04);
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = GetTwoOrFour();
                                break;
                            }
                        }
                        Console.WriteLine();
                        Scan();
                        break;
                    case ConsoleKey.RightArrow:
                        MoveRight();
                        while (true)
                        {
                            row = random.Next(04);
                            col = random.Next(04);
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = GetTwoOrFour();
                                break;
                            }
                        }
                        Console.WriteLine();
                        Scan();
                        break;
                }
 
            }
 
        }
        public void moveUp()
        {
            count = 1;
            for (int i = 0; i < 4; i++)
            {
                for (int row = 0; row < 4; row++)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row + 1, col];
                                arr[row + 1, col] = 0;
                            }
                        }
                    }
                }
            }
            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    if (row < 3)
                    {
                        if (arr[row, col] == arr[row + 1, col])
                        {
                            arr[row, col] = arr[row, col] + arr[row + 1, col];
                            arr[row + 1, col] = 0;
                        }
                    }
                }
            }
 
            for (int i = 0; i < 4; i++)
            {
                for (int row = 0; row < 4; row++)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row + 1, col];
                                arr[row + 1, col] = 0;
                            }
                        }
                    }
                }
            }
 
        }
        public void MoveDown()
        {
            count = 2;
            for (int i = 0; i < 4; i++)
            {
                for (int row = 3; row >= 0; row--)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row - 1, col];
                                arr[row - 1, col] = 0;
                            }
                        }
                    }
                }
            }
 
 
            for (int row = 3; row >= 0; row--)
            {
                for (int col = 0; col < 4; col++)
                {
                    if (row > 0)
                    {
                        if (arr[row, col] == arr[row - 1, col])
                        {
                            arr[row, col] = arr[row, col] + arr[row - 1, col];
                            arr[row - 1, col] = 0;
                        }
                    }
                }
            }
 
 
            for (int i = 0; i < 4; i++)
            {
                for (int row = 3; row >= 0; row--)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row - 1, col];
                                arr[row - 1, col] = 0;
                            }
                        }
                    }
                }
            }
        }
        public void MoveLeft()
        {
            count = 3;
            for (int i = 0; i < 4; i++)
            {
                for (int col = 0; col <4; col++)
                {
                    for (int row = 0; row < 4; row++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row , col+1];
                                arr[row, col+1= 0;
                            }
                        }
                    }
                }
            }
 
 
            for (int col = 0; col < 4; col++)
            {
                for (int row = 0; row < 4; row++)
                {
                    if (col < 3)
                    {
                        if (arr[row, col] == arr[row, col+1])
                        {
                            arr[row, col] = arr[row, col] + arr[row, col+1];
                            arr[row, col+1= 0;
                        }
                    }
                }
            }
 
 
            for (int i = 0; i < 4; i++)
            {
                for (int col = 0; col < 4; col++)
                {
                    for (int row = 0; row < 4; row++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row, col + 1];
                                arr[row, col + 1= 0;
                            }
                        }
                    }
                }
            }
        }
        public void MoveRight()
        {
            count = 4;
            for (int i = 0; i < 4; i++)
            {
                for (int col = 3; col > 0; col--)
                {
                    for (int row = 0; row < 4; row++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row, col - 1];
                                arr[row, col - 1= 0;
                            }
                        }
                    }
                }
            }
            for (int col = 3; col > 0; col--)
            {
                for (int row = 0; row < 4; row++)
                {
                    if (col > 0)
                    {
                        if (arr[row, col] == arr[row, col - 1])
                        {
                            arr[row, col] = arr[row, col] + arr[row, col - 1];
                            arr[row, col - 1= 0;
                        }
                    }
                }
            }
 
            for (int i = 0; i < 4; i++)
            {
                for (int col = 3; col > 0; col--)
                {
                    for (int row = 0; row < 4; row++)
                    {
                        bool b = Check(row, col);
                        if (b == true)
                        {
                            if (arr[row, col] == 0)
                            {
                                arr[row, col] = arr[row, col - 1];
                                arr[row, col - 1= 0;
                            }
                        }
                    }
                }
            }
        }
        public bool Check(int row, int col)
        {
            if (count == 1)
            {
                row = row + 1;
                if (row < 4)
                {
                    switch (arr[row, col])
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 8:
                        case 16:
                        case 32:
                        case 64:
                        case 128:
                        case 256:
                        case 512:
                        case 1024:
                        case 2048:
                            return true;
                        default:
                            return true;
                    }
                }
            }
            if (count == 2)
            {
                row = row - 1;
                if (row >= 0)
                {
                    switch (arr[row, col])
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 8:
                        case 16:
                        case 32:
                        case 64:
                        case 128:
                        case 256:
                        case 512:
                        case 1024:
                        case 2048:
                            return true;
                        default:
                            return false;
                    }
                }
            }
            if (count == 3)
            {
                col = col + 1;
                if (col < 4)
                {
                    switch (arr[row, col])
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 8:
                        case 16:
                        case 32:
                        case 64:
                        case 128:
                        case 256:
                        case 512:
                        case 1024:
                        case 2048:
                            return true;
                        default:
                            return false;
                    }
                }
            }
            if (count == 4)
            {
                col = col - 1;
                if (col >=0)
                {
                    switch (arr[row, col])
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 8:
                        case 16:
                        case 32:
                        case 64:
                        case 128:
                        case 256:
                        case 512:
                        case 1024:
                        case 2048:
                            return true;
                        default:
                            return false;
                    }
                }
            }
            return false;
        }
 
        public int GetTwoOrFour()
        {
            int num = random.Next(0100);
 
            if (num > 50)
            {
                return 4;
            }
            return 2;
        }
        public void Scan()
        {
            Console.WriteLine(" -----------------------------------------");
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Console.Write(" ||      ");
                    Console.Write(arr[i, j]);
 
                }
                Console.Write("||");
                Console.WriteLine();
                Console.WriteLine(" -----------------------------------------");
            }
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

:

2를 왼쪽 끝으로 갔다가 밑에 쭈욱 내리다가 지그재그로 원상복귀시키기(19.10.23)

Console(콘솔)/실습 2019. 10. 23. 14:40

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax101
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax101
{
    public class App
    {
        private int[,] arr = new int[35];
        int count= 0;
        public App()
        {
            arr[04= 2;
            MoveLeft(4,0);
 
            for(int i = 0; i < 3; i++)
            {
                for(int j = 0; j < 5; j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            MoveDown(00);
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Move(0-2);
        }
        public void MoveLeft(int x,int y)//좌표 (4,0)
        {
            if( y < 0)
            {
                y = y * -1;
            }
            int row = y;
            int col = x;
            var val = this.arr[row, col];
            bool a = this.ChackLeft(row, col);
            if(a == true)
            {
                this.arr[row, col-1= val;
                this.arr[row, col] = 0;
                this.MoveLeft(col-1, row);
            }
            else
            {
                return;
            }
 
        }
        public bool ChackLeft(int row ,int col)
        {
            col = col - 1;
            if(col >=0)
            switch (arr[row, col])
            {
                case 0:
                    return true;
                default:
                    return false;
            }
            return false;
        }
        public void MoveDown(int x,int y)//좌표(0,0)
        {
            if(y < 0)
            {
                y = y * -1;
            }
            int row = y;
            int col = x;
            var val = this.arr[row, col];
            bool a = this.ChackDown(row, col);
            if(a == true)
            {
                this.arr[row + 1, col] = val;
                this.arr[row, col] = 0;
                this.MoveDown(col, row-1);
            }
            else
            {
                return;
            }
        }
        public bool ChackDown(int row,int col)
        {
            row = row + 1;
            if(row <= 2)
            {
                switch(arr[row,col])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            return false;
        }
        public void Move(int x, int y)
        {
            if (y < 0)
            {
                y = y * -1;
            }
            int row = y;
            int col = x;
            var val = arr[row, col];
            if (count == 0)
            {
                bool a = Chack(row, col);
                if (a == true && col < 2)
                {
                    arr[row, col + 1= val;
                    arr[row, col] = 0;
                    this.Move(col + 1, row);
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Console.Write(arr[i, j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    count = 1;
                    this.Move(col, row);
                }
            }
            else if (count == 1)
            {
                bool a = Chack(row, col);
                if (a == true || row >1)
                {
                    arr[row - 1, col] = val;
                    arr[row, col] = 0;
                    this.Move(col, row - 1);
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Console.Write(arr[i, j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    count= 2;
                    this.Move(col, row);
                }
            }
            else if (count == 2)
            {
                bool a = Chack(row, col);
                if (a == true && col < 3)
                {
                    arr[row, col + 1= val;
                    arr[row, col] = 0;
                    this.Move(col + 1, row);
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Console.Write(arr[i, j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    count = 3;
                    this.Move(col, row);
                }
 
            }
            else if (count == 3)
            {
                bool a = Chack(row, col);
                if (a == true || row > 0)
                {
                    arr[row - 1, col] = val;
                    arr[row, col] = 0;
                    this.Move(col, row - 1);
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Console.Write(arr[i, j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    count = 4;
                    this.Move(col, row);
                }
            }
            else if (count == 4)
            {
                bool a = Chack(row, col);
                if (a == true)
                {
                    arr[row, col + 1= val;
                    arr[row, col] = 0;
                    this.Move(col + 1, row);
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Console.Write(arr[i, j]);
                        }
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                    return;
                }
            }
 
        }
        public bool Chack(int row,int col)
        {
            if (count == 0)
            {
                switch (arr[row, col+1])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            else if(count == 1 && row - 1 > 0)
            {
                switch (arr[row-1, col])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            else if (count == 2)
            {
                switch (arr[row, col + 1])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            else if (count == 3 && row - 1 >= 0)
            {
                switch (arr[row - 1, col])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            else if (count == 4 && col + 1 <5)
            {
                switch (arr[row, col + 1])
                {
                    case 0:
                        return true;
                    default:
                        return false;
                }
            }
            return false;
        }
 
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

:

C# 백준 1773번 문제 (19.10.22)

Console(콘솔)/알고리즘 2019. 10. 22. 08:42

https://www.acmicpc.net/problem/1773

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
 
namespace Syntax93
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            if (1 <= int.Parse(str[0]) && int.Parse(str[0]) <= 100)
            {
                if (1 <= int.Parse(str[1]) && int.Parse(str[1]) <= 2000000)
                {
                    int N = int.Parse(str[0]);
                    int C = int.Parse(str[1]);
                    int[] arr = new int[C];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        arr[i] = i + 1;
                    }
                    for (int i = 0; i < N; i++)
                    {
                        int input = int.Parse(Console.ReadLine());
                        if (1 <= input && input <= C)
                        {
                            for (int j = 0; j < arr.Length; j++)
                            {
                                if (arr[j] % input == 0)
                                {
                                    arr[j] = -1;
                                }
                            }
                        }
                    }
                    int count = 0;
                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i] == -1)
                        {
                            count++;
                        }
                    }
                    Console.WriteLine(count);
                }
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

:

C# 백준 2167 문제(19.10.21)

Console(콘솔)/알고리즘 2019. 10. 21. 17:21

https://www.acmicpc.net/problem/2167

 

2167번: 2차원 배열의 합

첫째 줄에 배열의 크기 N, M(1 ≤ N, M ≤ 300)이 주어진다. 다음 N개의 줄에는 M개의 정수로 배열이 주어진다. 배열에 포함되어 있는 수는 절댓값이 10,000보다 작거나 같은 정수이다. 그 다음 줄에는 합을 구할 부분의 개수 K(1 ≤ K ≤ 10,000)가 주어진다. 다음 K개의 줄에는 네 개의 정수로 i, j, x, y가 주어진다(i ≤ x, j ≤ y).

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
 
namespace Syntax92
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arrstr1 = Console.ReadLine().Split(' ');
            int[,] arrInput = new int[int.Parse(arrstr1[0]), int.Parse(arrstr1[1])];
            if (1 <= int.Parse(arrstr1[0]) && int.Parse(arrstr1[1]) <= 300)
            {
                for (int i = 0; i < int.Parse(arrstr1[0]); i++)
                {
                    string[] arrstr2 = Console.ReadLine().Split(' ');
                    for (int j = 0; j < int.Parse(arrstr1[1]); j++)
                    {
                        if (-10000 <= int.Parse(arrstr2[j]) && int.Parse(arrstr2[j]) <= 10000)
                        {
                            arrInput[i, j] = int.Parse(arrstr2[j]);
                        }
                    }
                }
                int K = int.Parse(Console.ReadLine());
                int[] arrInput1 = new int[K];
                if (1 <= K && K <= 10000
                {
                    for(int a = 0; a < K; a++)
                    {
                        int sum = 0;
                        string[] arrstr3 = Console.ReadLine().Split(' ');
                        int i = int.Parse(arrstr3[0])-1;
                        int j = int.Parse(arrstr3[1])-1;
                        int x = int.Parse(arrstr3[2])-1;
                        int y = int.Parse(arrstr3[3])-1;
                        if (i <= x && j <= y)
                        {
                            for(int b = i; b <= x; b++)
                            {
                                for (int c = j; c <= y; c++)
                                {
                                    sum = sum + arrInput[b, c];
                                }
                            }
                            arrInput1[a] = sum;
                        }
                    }
                }
                Console.Clear();
                for (int i = 0; i < arrInput1.Length; i++)
                {
                    Console.WriteLine(arrInput1[i]);
                }
            }
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

:

C# 백준 10818 최솟값 최댓값

Console(콘솔)/알고리즘 2019. 10. 18. 11:35

 

https://www.acmicpc.net/problem/10818

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
 
namespace Syntax
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            if (1 <= N && N <= 1000000)
            {
                string[] str = Console.ReadLine().Split(' ');
                int[] arr = new int[N];
                int max = -1000000;
                int min= 1000000;
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = int.Parse(str[i]);
                    if (max < arr[i])
                    {
                        max = arr[i];
                    }
                    if (min > arr[i])
                    {
                        min = arr[i];
                    }
                }
                Console.Clear();
                Console.WriteLine($"{min} {max}");
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

:

C# 백준 2562 문제 최댓값

카테고리 없음 2019. 10. 18. 10:40

 

https://www.acmicpc.net/problem/2562

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
 
namespace Syntax
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr1 = new int[9];
            for(int i = 0; i < arr1.Length; i++)
            {
                arr1[i] = int.Parse(Console.ReadLine());
            }
            int max = 0;
            int amount = 0;
            for(int i = 0; i < arr1.Length; i++)
            {
                if(max < arr1[i])
                {
                    max = arr1[i];
                    amount = i + 1;
                }
            }
            Console.Clear();
            Console.WriteLine($"{max}");
            Console.WriteLine($"{amount}");
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

: