思路
暴力把全部数加起来多做几次就可以了
#include
#include
using namespace std;
char st[1000];
int main()
{
int ans;
scanf("%s",st);
int len=strlen(st);
while (len!=1)
{
ans=0;
for (int i=1;i<=len;i++)
{
ans=ans+int(st[i-1])-48;
}
strcpy(st,"");
sprintf(st,"%d",ans);
len=strlen(st);
}
ans=int(st[0])-48;
printf("%d\n",ans);
return 0;
}
Comments NOTHING