|
|
вернуться в форумWrong Anser: BUT I checked with the test data on this site....correct.... Wrong Anser: BUT I checked with the test data on this site....correct.... take a look at my code please. thanks. is there any test case that does not work?? // USU Problem 1165 // Subnumber // Done by Teh Ming Han #include <string.h> #include <iostream.h> #include <stdlib.h> int main(){ int i,a,pos,mat=-1,ori=-1,n=0; char dat[201]={'\0'}; cin.getline(dat,200,'\n');
pos=0; int length = strlen(dat); for (i=1;true;i++){ char ne[8]={'\0'}; itoa(i,ne,10); for (a=0;a<strlen(ne);a++){ n++; if (ne[a]==dat[pos]){ if (pos==0) ori = n; pos++; }else pos=0; if (pos==length){ mat = ori; break; } } if (mat!=-1) break; } cout<<mat; return 0; } Re: Wrong Anser: BUT I checked with the test data on this site....correct.... > Wrong Anser: BUT I checked with the test data on this > site....correct.... > > take a look at my code please. > thanks. is there any test case that does not work?? > here! 9100 your output is 2889 99100 your output is 188 91001 your output is 38939 > // USU Problem 1165 > // Subnumber > // Done by Teh Ming Han > > #include <string.h> > #include <iostream.h> > #include <stdlib.h> > > int main(){ > int i,a,pos,mat=-1,ori=-1,n=0; > char dat[201]={'\0'}; > cin.getline(dat,200,'\n'); > > pos=0; > int length = strlen(dat); > for (i=1;true;i++){ > char ne[8]={'\0'}; > itoa(i,ne,10); > for (a=0;a<strlen(ne);a++){ > n++; > if (ne[a]==dat[pos]){ > if (pos==0) ori = n; > pos++; > }else pos=0; > if (pos==length){ > mat = ori; > break; > } > } > if (mat!=-1) break; > } > cout<<mat; > return 0; > } |
|
|