문제 출처: www.acmicpc.net/problem/11021
11021번: A+B - 7
각 테스트 케이스마다 "Case #x: "를 출력한 다음, A+B를 출력한다. 테스트 케이스 번호는 1부터 시작한다.
www.acmicpc.net
1. 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
int T, A, B; | |
cin >> T; | |
for (int i = 1; i <= T; i++) | |
{ | |
cin >> A >> B; | |
cout << "Case #" << i << ": " << A + B << endl; | |
} | |
return 0; | |
} |
2. 풀이
int T, A, B;
cin >> T;
테스트 케이스의 횟수를 제일 처음에 입력하기에 T를 선언 후 입력을 한다.
for (int i = 1; i <= T; i++)
{
cin >> A >> B;
cout << "Case #" << i << ": " << A + B << endl;
}
반복문을 이용하여 입력과 출력을 제어했는데 A와 B를 입력 후 i의 값을 이용하여 #뒤에 있는 숫자를 출력하게 한 뒤 예제 출력과 똑같은 배치를 해주고 출력을 해주면 끝이다.
'컴퓨터 > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 10871번: X보다 작은 수 [C++] (0) | 2020.12.16 |
---|---|
백준 알고리즘 2439번: 별 찍기 - 2 [C++] (0) | 2020.12.15 |
백준 알고리즘 2742번: 기찍 N [C++] (0) | 2020.12.07 |
백준 알고리즘 15552번: 빠른 A+B [C++] (0) | 2020.12.04 |
백준 알고리즘 8393번: 합 [C++][재귀] (0) | 2020.12.03 |