fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. int flag(char c)
  4. {
  5. if(c=='r')
  6. return 1;
  7. else if(c=='w')
  8. return 0;
  9. else
  10. return 2;
  11. }
  12. int main()
  13. {
  14. char str[1000000];
  15. int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
  16. char p, ic;
  17. scanf("%d", &n);
  18. gets(str);
  19. while(str[i]=='w')
  20. i++;
  21. if(str[i]==str[n-1])
  22. fl=1;
  23. else
  24. fl=0;
  25. }
  26. while(i<n)
  27. {
  28. if(i>0 && str[i-1]=='w')
  29. {
  30. while(str[i-1]=='w')
  31. i--;
  32. }
  33.  
  34. k=i+1;
  35. p=str[i];
  36. f=flag(str[i]);
  37. while(str[i+1]=='w'||str[i+1]==str[i]||(str[i]=='w' && ((flag(str[i+1])==f)||f==0)))
  38. {
  39. c++;
  40. i++;
  41. }
  42. count[j++]=i-k+2;
  43. i++;
  44. }
  45. if(fl==1)
  46. count[j-1]+=count[0];
  47. max=0;
  48. for(i=0; i<j-1; i++)
  49. {
  50. if((count[i]+count[i+1])>max)
  51. max=count[i]+count[i+1];
  52. }
  53. printf("%d",max);
  54. return 0;
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
wwww
compilation info
prog.c: In function ‘main’:
prog.c:19:5: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
     gets(str);
     ^
prog.c:16:13: warning: unused variable ‘ic’ [-Wunused-variable]
     char p, ic;
             ^
prog.c:16:10: warning: unused variable ‘p’ [-Wunused-variable]
     char p, ic;
          ^
prog.c:15:53: warning: unused variable ‘max’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                                                     ^
prog.c:15:49: warning: variable ‘fl’ set but not used [-Wunused-but-set-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                                                 ^
prog.c:15:46: warning: unused variable ‘f’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                                              ^
prog.c:15:43: warning: unused variable ‘k’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                                           ^
prog.c:15:38: warning: unused variable ‘c’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                                      ^
prog.c:15:22: warning: unused variable ‘count’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                      ^
prog.c:15:17: warning: unused variable ‘j’ [-Wunused-variable]
     int n, i=0, j=0, count[1000000], c=0, k, f, fl, max;
                 ^
prog.c: At top level:
prog.c:27:5: error: expected identifier or ‘(’ before ‘while’
     while(i<n)
     ^
prog.c:46:5: error: expected identifier or ‘(’ before ‘if’
     if(fl==1)
     ^
prog.c:48:5: warning: data definition has no type or storage class [enabled by default]
     max=0;
     ^
prog.c:48:5: warning: type defaults to ‘int’ in declaration of ‘max’ [-Wimplicit-int]
prog.c:49:5: error: expected identifier or ‘(’ before ‘for’
     for(i=0; i<j-1; i++)
     ^
prog.c:49:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
     for(i=0; i<j-1; i++)
               ^
prog.c:49:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
     for(i=0; i<j-1; i++)
                      ^
prog.c:54:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("%d",max);
            ^
prog.c:54:17: error: expected declaration specifiers or ‘...’ before ‘max’
     printf("%d",max);
                 ^
prog.c:55:5: error: expected identifier or ‘(’ before ‘return’
     return 0;
     ^
prog.c:56:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
prog.c: In function ‘main’:
prog.c:26:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
stdout
Standard output is empty