fork(1) download
  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. int wstr(char *s,int len)
  5. {
  6. int p[26]={0},q[26]={0},r[26]={0},t[26]={0},*a,*b,*c,*d,*temp;
  7. int max1=0,max2=0,max3=0,max4=0,i=0,j,totmax=0;
  8. a=p,b=q,c=r,d=t;
  9. for(;i<len && s[i]!='#';i++)
  10. {
  11. a[s[i]-97]++;
  12. if(max1<a[s[i]-97])
  13. max1=a[s[i]-97];
  14. }
  15. if(s[i]=='#')
  16. i++;
  17. for(;i<len && s[i]!='#';i++)
  18. {
  19. b[s[i]-97]++;
  20. if(max2<b[s[i]-97])
  21. max2=b[s[i]-97];
  22. }
  23. if(s[i]=='#')
  24. i++;
  25. for(;i<len && s[i]!='#';i++)
  26. {
  27. c[s[i]-97]++;
  28. if(max3<c[s[i]-97])
  29. max3=c[s[i]-97];
  30. }
  31. if(s[i]=='#')
  32. i++;
  33. while(i<len)
  34. {
  35. while(i<len && s[i]!='#')
  36. {
  37. d[s[i]-97]++;
  38. if(max4<d[s[i]-97])
  39. max4=d[s[i]-97];
  40. i++;
  41. }
  42. if(totmax<(max1+max2+max3+max4) && max1 && max2 && max3 && max4)
  43. totmax=max1+max2+max3+max4;
  44. max1=max2;
  45. max2=max3;
  46. max3=max4;
  47. max4=0;
  48. temp=a;
  49. a=b;
  50. b=c;
  51. c=d;
  52. d=temp;
  53. for(int j=0;j<26;j++)
  54. d[j]=0;
  55. if(s[i]=='#')
  56. i++;
  57. }
  58. if(totmax)
  59. return (totmax+3);
  60. return 0;
  61. }
  62. int main()
  63. {
  64. int t,i=0,len;
  65. cin>>t;
  66. int res[t];
  67. char *s,ch;
  68. while(i<t)
  69. {
  70. len=0;
  71. s=new char[10000];
  72. while((ch=getchar()))
  73. {
  74. if(ch==' ' || ch=='\n')
  75. break;
  76. s[len++]=ch;
  77. }
  78. s[len]=0;
  79. if(!len)
  80. continue;
  81. res[i]=wstr(s,len);
  82. delete []s;
  83. i++;
  84. }
  85. for(i=0;i<t;cout<<res[i]<<endl,i++);
  86. return 0;
  87. }
Runtime error #stdin #stdout 0.04s 2992KB
stdin
3
aaaaa#bb#cc#dddd
acb#aab#bab#accba
abc#dda#bb#bb#aca
stdout
Standard output is empty