USACO1.1.4 - Broken Necklace
【摘要】
/*
ID:gwj11391
LANG:C++
TASK:beads
*/
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
using namespace std;
int main(){
...
/*
ID:gwj11391
LANG:C++
TASK:beads
*/
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
using namespace std;
int main(){
ifstream fin("beads.in");
ofstream fout("beads.out");
int n, ans = -1;
string s;
fin>>n>>s;
s += s; s += s;
for(int i = n; i < s.size(); i++){
int j1 = i-1, j2 = i, j3, sum = 0;
while(++j1 < s.size() && s[j1] == s[i] || s[j1] == 'w') sum++;
while(--j2 >= 0 && s[j2] == 'w') sum++; j3 = j2;
while(--j3 >= 0 && s[j3] == s[j2] || s[j3] == 'w') sum++;
ans = max(ans, sum);
}
ans>n? fout<<n<<"\n": fout<<ans+1<<"\n";
return 0;
}
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/68957218
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)