728x90
반응형
1769 3의 배수
문제풀이
#include <iostream>
#include <string>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
string s;
int a,cnt;
int main()
{
fast_io();
cin >> s;
while(s.length()!=1)
{
a=0;
cnt++;
for(int i=0;i<s.length();i++)
{
a+=s[i]-'0';
}
s=to_string(a);
}
a=s[0]-'0';
if(a<10)
{
cout << cnt << "\n";
if(a%3==0) cout << "YES";
else cout << "NO";
}
return 0;
}
재밌는 문제였다!
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 11659 구간 합 구하기 4 (0) | 2022.03.30 |
---|---|
백준 c++ 9095 1,2,3 더하기 (0) | 2022.03.30 |
백준 c++ 2776 암기왕 (0) | 2022.03.27 |
프로그래머스 c++ 가장 큰 수 (0) | 2022.03.23 |
프로그래머스 c++ k번째수 (0) | 2022.03.23 |