[BaekJoon] 5717번 - 상근이의 친구들 [Java][C++]
[BaekJoon] 5717번 - 상근이의 친구들 [Java][C++]
1. 문제 풀이
남자의 수와 여자의 수를 더한게 친구의 수이다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
while (true) {
st = new StringTokenizer(br.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
if (A == 0) break;
sb.append(A + B).append("\n");
}
System.out.println(sb);
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
while (true) {
int a, b;
cin >> a >> b;
if (a == 0) break;
cout << a + b << '\n';
}
}
This post is licensed under CC BY 4.0 by the author.