Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5.     char s[1000];
  6.     char ans[1000];
  7.     char curStr[1000];
  8.     scanf("%s", s);
  9.     int n = strlen(s);
  10.     int i = 0; int maxcnt = -1;
  11.     int isLastDigit = 0;
  12.     int curCnt = 0;
  13.     for (i = 0; i < n; i++) {
  14.         if (isLastDigit == 1) {
  15.             if (s[i] >= '0' && s[i] <= '9') {
  16.                 curCnt++;
  17.                 curStr[curCnt - 1] = s[i];
  18.             } else {
  19.                 if (maxcnt < curCnt) {
  20.                     int j = 0;
  21.                     maxcnt = curCnt;
  22.                     for (j = 0; j < maxcnt; j++)
  23.                     ans[j] = curStr[j];
  24.                     ans[maxcnt] = '\0';
  25.                 }
  26.                 curCnt = 0;
  27.                 isLastDigit = 0;
  28.                
  29.             }
  30.         } else {
  31.             if (s[i] >= '0' && s[i] <= '9') {
  32.                 isLastDigit = 1;
  33.                 curCnt = 1;
  34.                 curStr[curCnt - 1] = s[i];
  35.             }
  36.         }
  37.     }
  38.    
  39.     if (isLastDigit == 1) {
  40.         if (maxcnt < curCnt) {
  41.             int j = 0;
  42.             maxcnt = curCnt;
  43.             for (j = 0; j < maxcnt; j++)
  44.                 ans[j] = curStr[j];
  45.             ans[maxcnt] = '\0';
  46.         }
  47.  
  48.     }
  49.     if (maxcnt == -1) printf("-1");
  50.     else printf("%s", ans);
  51.    
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement