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 |
哪位高手帮忙看一下为什么是wrong answer阿 小弟感激不尽!!!#include <iostream.h> #include <strstrea.h> #include <string.h> char* inventory(char* cpNum); void main() { int i, j; char caFirst[80]; char* cpaInv[16]; while (1) { cin >> caFirst; if (!strcmp(caFirst, "-1") ) break; for (i = 0; i < 16; i++) cpaInv[i] = NULL; cpaInv[0] = caFirst; for (i = 0; i < 15; i++) { cpaInv[i + 1] = inventory(cpaInv[i] ); for (j = i; j >= 0; j--) if (!strcmp(cpaInv[i + 1], cpaInv[j] ) ) break; if (j == i) { if (!i) cout << caFirst << " is self-inventorying" << endl; else cout << caFirst << " is self-inventorying after " << j << " steps" << endl; break; } if (j >= 0) { cout << caFirst << " enters an inventory loop of length " << i - j + 1 << endl; break; } } if (i == 15) cout << caFirst << " can not be classified after 15 iterations" << endl; for (i = 1; cpaInv[ i ] && (i < 16); i++) delete [](cpaInv[ i ] ); } } char* inventory(char* cpNum) { int i; int iaNums[10] = { 0 }; char* cpNew; for (i = 0; cpNum[i]; i++) iaNums[cpNum[i] - '0']++; cpNew = new char[30]; ostrstream sout(cpNew,30); for (i = 0; i <= 9; i++) if (iaNums[i] ) sout << iaNums[i] << i; sout << '\0'; return cpNew; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator