|
|
вернуться в форумs.o. to test this ?? I can't see a problem in this soluton, but I get WA on test#3 I compared it with a lot of tests to a solution, that is surely correct - the results were always equal. #include <cstdlib> #include <cstdio> #include <cctype> int func(long pages,int dgts); char temp[10]; int main() { long pages; long dgts = 0; scanf("%i",&pages); char strpages[10]; sprintf(strpages,"%i",pages);
long j = 0;
while(isdigit(strpages[j])) { dgts++; ++j; }
if(pages > 100) { func(pages,dgts-1); system("pause"); return 0; }
int digits[] = {0,0,0,0,0,0,0,0,0,0}; for(long i = 1; i <= pages; ++i) { j = 0; sprintf(temp,"%i",i); while(isdigit(temp[j])) digits[temp[j++]-48]++; } for(long i = 0; i < 10; ++i) printf("%i\n",digits[i]);
system("pause"); return 0; } int func(long pages,int dgts) { long j = 0; long long_o, long_t; char* one = new char[dgts]; char* two = new char[dgts+1];
one[0] = dgts + 46; for(long k = 1; k < dgts-1; ++k) one[k] = '8';
one[dgts - 1] = '9'; long_o = atoi(one); two[0] = dgts + 48; for(long k = 1; k < dgts; ++k) two[k] = '0';
long_t = atoi(two);
long digits[10]; digits[0] = long_o; for(long i = 1; i < 10; ++i) digits[i] = long_t;
long start = 100; for(long i = 0; i < dgts - 2; ++i) start *= 10;
for(long i = start; i <= pages; ++i) { j = 0; sprintf(temp,"%i",i); while(isdigit(temp[j])) digits[temp[j++]-48]++; } for(long i = 0; i < 10; ++i) printf("%i\n",digits[i]); return 0; } Edited by author 05.10.2006 23:19 Re: s.o. to test this ?? Edited by author 05.10.2006 23:19 |
|
|