poj3617 Best Cow Line 贪心
题目连接#include<iostream>#include<string>using namespace std;int main(){int n;string s;char c;cin>>n;for(int i=0;i<n;i++){cin>>c;s+=c;}int a
·
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
string s;
char c;
cin>>n;
for(int i=0;i<n;i++){
cin>>c;
s+=c;
}
int a=0,b=s.size()-1;
int cnt=0;
while(a<=b){
bool left = false;
for(int i=0;a+i<=b;i++){
if(s[a+i]<s[b-i]){
left = true;
break;
}
else if(s[a+i]>s[b-i]){
left = false;
break;
}
}
cnt++;
if(left) cout<<s[a++];
else cout<<s[b--];
if(cnt==80){//80个字符换行
cout<<endl;
cnt=0;
}
}
cout<<endl;
}
更多推荐
已为社区贡献1条内容
所有评论(0)