Advertisement
nullzero

gets + sscanf + strstr + sprintf

Aug 16th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. const int N(100);
  5.  
  6. char str[N];
  7.  
  8. int main(){
  9.     int len = strlen(gets(str));
  10.     int now = 0;
  11.     int hh, mm;
  12.     while(now < len){
  13.         while(now < len and *(str + now) == ' ') ++now;
  14.         if(now == len) break;
  15.         if(sscanf(str + now, "%d:%d", &hh, &mm) < 1) break;
  16.         printf("get %02d:%02d\n", hh, mm);
  17.         char* next = strstr(str + now, " ");
  18.         if(next == 0) break;
  19.         now = next - str;
  20.     }
  21.     sprintf(str, "%d+%d=%d", hh, mm, hh + mm);
  22.     printf("%s", str);
  23.     return 0;
  24. }
  25.  
  26. /*
  27.          23:58                 43:12             02:43              1:32    
  28. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement