Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
前面评论说的测试通过,但是WA// 1616.cpp : 定义控制台应用程序的入口点。 // #include <iostream> using namespace std; char num[16][80];//输入数字 int index; //压缩次数 int main() { while (cin >> num[0]) { if (num[0][0] == '-') { break; } bool isTag; for (index = 1; index < 16; index++) { int times[10] = { 0 };//数字出现次数 isTag = false; int lastIndex = index - 1; for (int i = 0; num[lastIndex][i]; i++) { times[num[lastIndex][i] - '0']++; } //新的数字 int newCharIndex = 0; for (int i = 0; i < 10; i++) { if (times[i] == 0) { continue; } else if (times[i] < 10) { num[index][newCharIndex] = times[i] + '0'; newCharIndex++; } else { num[index][newCharIndex] = times[i] % 10 + '0'; newCharIndex++; num[index][newCharIndex] = times[i] / 10 + '0'; newCharIndex++; } num[index][newCharIndex] = i + '0'; newCharIndex++; } num[index][newCharIndex] = '\0'; if (index == 1) { //新的数字与原来的数字相同 if (!strcmp(num[index], num[lastIndex])) { isTag = true; cout << num[0] << " is self-inventorying" << endl; break; } } else { if (!strcmp(num[index], num[lastIndex])) { isTag = true; cout << num[0] << " is self-inventorying after " << lastIndex << " steps" << endl; break; } //新的数字与第一个数字相同 else { int i; for (i = index - 2; i >= 0; i--) { if (!strcmp(num[index], num[i])) { isTag = true; break; } } if (isTag) { cout << num[0] << " enters an inventory loop of length " << index - i << endl; break; } } } } if (!isTag) { cout << num[0] << " can not be classified after 15 iterations" << endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator