ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1151. Radiobeacons

Help , please . How to read string in this problem ???
Posted by A.Ferdinand 28 Jun 2006 22:37
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.
Posted by Mehas (PSU #2) 28 Aug 2006 11:11
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);
     }
}