백준 BOJ C# 15552 빠른 A+B

2020. 1. 10. 16:44백준 알고리즘 단계별/for 문

반응형


출제 링크 : https://www.acmicpc.net/problem/15552

 

15552번: 빠른 A+B

첫 줄에 테스트케이스의 개수 T가 주어진다. T는 최대 1,000,000이다. 다음 T줄에는 각각 두 정수 A와 B가 주어진다. A와 B는 1 이상, 1,000 이하이다.

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
using System;
using static System.Console;
using System.Text;
using System.IO;
 
namespace baekjoon
{
    class MainApp
    {
        static void Main(string[] args)
        {
            //입력 : T개의 개수 받아오기
            int maxT = int.Parse(Console.ReadLine());
            int[] aNum = new int[maxT];
            int[] bNum = new int[maxT];
            StringBuilder abNumbers = new StringBuilder();
 
            //T줄 만큼 반복되고 A,B받아오기
            for (int i = 0; i < maxT; i++)
            {
                string[] ab = Console.ReadLine().Split(); // 입력받을때 Split으로 잘라 배열로 만듬
                aNum[i] = int.Parse(ab[0]);
                bNum[i] = int.Parse(ab[1]);
                abNumbers.Append(aNum[i] + bNum[i] + "\n");
 
            }
            //받아온 값 더하기
            WriteLine(abNumbers.ToString());
        }
    }
}

이번 문제는 엄청 어려웠다...

 

C# 구문
StreamReader로 읽고, StringBuilder로 출력을 모아 놓았다가 그 String을 Console.WriteLine하는 방법이 있습니다. BufferedStream과 StringWriter로 조금 더 향상시킬 수 있는 것 같으나 자세한 것은 다른 분의 답변을 기다리겠습니다.

 

기존  for문 사용과 StringBuilder 을 활용해야되고 아직 사용하지 못한 StringReader을 통해 받아오지 못했다.

https://morm.tistory.com/28?category=724725

 

[백준 3단계(4)] 15552번: 빠른 A+B, C#풀이

https://www.acmicpc.net/problem/15552 15552번: 빠른 A+B 첫 줄에 테스트케이스의 개수 T가 주어진다. T는 최대 1,000,000이다. 다음 T줄에는 각각 두 정수 A와 B가 주어진다. A와 B는 1 이상, 1,000 이하이다...

morm.tistory.com

결국 구글링 끝에 찾아낸 해답... 밑에는 풀기 위해 찾았던 자료들을 모아두었다.

 

https://nowonbun.tistory.com/131

https://morm.tistory.com/27

http://www.csharpstudy.com/Data/File-text.aspx

https://qzqz.tistory.com/251

 

 

반응형