|
|
back to boardHelp , please . How to read string in this problem ??? I'm sure I got WA because of reading string. Please help me, thanks. Here is my code to read string : ... fscanf(stdin,"%d\n",&m) ; for(int i=0;i<m;i++) { char s[1000] ; int j = 0 , k = 0 ; fscanf(stdin,"%s",&s) ; while ( s[j] != ',' ) a[i].x = a[i].x * 10 + s[j++] - 48 ; j++ ; while ( s[j] != ':' ) a[i].y = a[i].y * 10 + s[j++] - 48 ; j++ ; while (j < strlen(s) ) { while ( s[j] != '-' ) b[i][k] = b[i][k] * 10 + s[j++] - 48 ; j++ ; while ( j < strlen(s) && s[j] != ',' ) c[i][k] = c[i][k] * 10 + s[j++] - 48 ; k++ ; if ( s[j] == '\n' ) { j++ ; break ; } j++ ; } deg[i] = k ; } Use the Force, Luk. Here is my code for reading input. scanf("%d\n",&n); int i; int id,x,y,r; for (i = 0 ; i<n ; i++){ scanf("%d,%d:",&x,&y); while (true){ scanf("%d-%d",&id,&r); a[id][cnt[id]].x = x; a[id][cnt[id]].y = y; a[id][cnt[id]].r = r; cnt[id]++; char ch; ch = getc(stdin); if (ch!=',') break; }
} Re: Use the Force, Luk. Here is my code for reading input. Posted by r1d1 27 Aug 2010 05:12 or: for (int i=0; i<m; i++){ char buf; cin >> tmp.x >> buf >> tmp.y; while ((buf=cin.get())!='\n' && buf!=EOF){ int id; cin >> id >> buf >>tmp.r; a[id].push_back(tmp); } } |
|
|