1110번 - 더하기 사이클
#include <iostream>#include <cstdio>using namespace std;
int main() { int n,x=0,y=0; int t=0,cnt=0; scanf_s("%d", &n); if (n < 0 || n>99) { return 0; } int result = n; while ((y * 10 + (t % 10)) != result) { x = n / 10; y = n % 10; t = x + y; n = y * 10 + (t % 10); cnt++; }
cout << cnt << endl; return 0;}
뭐가 문제일까요...ㅠㅠ
0이 0으로 돌아오려면 1번은 거쳐야 되는데, 0이 출력되네요.
댓글을 작성하려면 로그인해야 합니다.
jisub3054 6년 전
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n,x=0,y=0;
int t=0,cnt=0;
scanf_s("%d", &n);
if (n < 0 || n>99) {
return 0;
}
int result = n;
while ((y * 10 + (t % 10)) != result) {
x = n / 10;
y = n % 10;
t = x + y;
n = y * 10 + (t % 10);
cnt++;
}
cout << cnt << endl;
return 0;
}
뭐가 문제일까요...ㅠㅠ