題目:計算一個序列,每個元素德語前一個串的長度,求第幾個序列和前面的相同。
分析:簡單題。直接模擬運行即可。
說明:注意數組開大一點繁殖溢出,╮(╯▽╰)╭。
#include <cstring>
#include <cstdlib>
#include <cstdio>
char buf[10001];
int main()
{
while (gets(buf)) {
if (!strcmp(buf, "END")) {
break;
}
int length = strlen(buf);
if (length == 1 && buf[0] == '1') {
puts("1");
}else {
int value = length;
int circle = 1;
while (true) {
int temp = value;
length = 0;
while (temp) {
temp /= 10;
length ++;
}
circle ++;
if (length == value) {
break;
}else {
value = length;
}
}
printf("%d\n",circle);
}
}
return 0;
}