1 条题解
-
0
C++ :
#include<stdio.h> #include<string.h> int inc(int x, int n){ x++; if(x == n) x = 0; return x; } int del(int x, int n){ x--; if(x < 0) x = n-1; return x; } int main(){ //freopen("beads.in","r",stdin); //freopen("beads.out","w",stdout); int n, ans, i, j; char str[400], c; int a[400], b[400]; while(scanf("%d", &n) != EOF){ scanf("%s", str); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(i = 0; i < n; i++){ if(str[i] != 'w'){ c = str[i]; j = inc(i, n); while(j != i){ a[i]++; if(str[j] != c && str[j] != 'w') break; j = inc(j, n); } j = del(i, n); c = str[j]; while(j != i){ b[i]++; j = del(j, n); if(c != 'w' && str[j] != c && str[j] != 'w') break; if(c == 'w') c = str[j]; } } } for(i = ans = 0; i < n; i++){ if(a[i]+b[i] > ans) ans = a[i]+b[i]; } if(ans > n || ans == 0) ans = n; printf("%d\n", ans); } return 0; }
- 1
信息
- ID
- 1198
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者