https://www.acmicpc.net/problem/10952
10952번: A+B - 5
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
방법 1
#include <iostream>
using namespace std;
int main() {
int A, B;
while (1) {
cin >> A >> B;
if (A == 0 & B == 0)
break;
cout << A + B << "\n";
}
}
방법 2
#include<stdio.h>
int main(){
int a,b;
while(1){
scanf("%d %d",&a,&b);
if(a==0 && b==0) break;
printf("%d\n",a+b);
}
}
https://www.acmicpc.net/problem/10951
10951번: A+B - 4
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
방법 1 - bool overloading
#include <iostream>
using namespace std;
int main() {
int A, B;
while (cin >> A >> B) {
cout << A + B << "\n";
}
}
방법 2
#include <iostream>
using namespace std;
int main() {
int A, B;
while (!(cin >> A >> B).eof()) {
cout << A + B << "\n";
}
}
방법 3
#include <iostream>
using namespace std;
int main() {
int A, B;
while (cin.eof() == true) {
cout << A + B << "\n";
}
}
방법 4
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d %d",&a,&b) != EOF)
printf("%d\n",a+b);
}
https://www.acmicpc.net/problem/1110
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
방법 1
#include <iostream>
using namespace std;
int main() {
int N, A, B;
cin >> N;
int count = 0;
int init = N;
while (1) {
count++;
A = N / 10;
B = N % 10;
N = 10 * B + (A + B) % 10;
if (init == N)
break;
}
cout << count;
}
방법 2
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int A, cnt = 0, init = N;
do {
cnt++;
N = 10 * (N % 10) + (N / 10 + N % 10) % 10;
} while (N != init);
cout << cnt;
}
방법 3
#include<stdio.h>
int main(){
int n, init, cnt=0;
scanf("%d",&n);
init=n;
do{
cnt++;
n=(n%10)*10+(n/10+n%10)%10;
}
while(n!=init);
printf("%d",cnt);
}