Best Cow Line POJ - 3617
2017-04-01 09:16
323 查看
题意:用给定字符串,通过两种操作,拼出字典序最小的字符串(1.从s头删除一个字符,加到t;2.从s尾删除一个字符,加到t;)
注意:1.每行输出至多80个
2.如果头尾相同,比较下一个
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a,b,m=0;
char s[2010],ss[2];
bool f;
int main()
{
scanf ("%d",&n);
for (int i=0;i<n;i++) {
scanf ("%s",ss);
s[i]=ss[0];
}
a=0;b=n-1;
while (a<=b) {
f=false;
for (int i=0;i+a<=b;i++) {
if (s[a+i]<s[b-i]) {
f=true;
break;
}
else if (s[a+i]>s[b-i]) {
f=false;
break;
}
}
if (f) {
putchar(s[a++]);
m++;
}
else {
putchar(s[b--]);
m++;
}
if (m%80==0) puts("");
}
return 0;
}
注意:1.每行输出至多80个
2.如果头尾相同,比较下一个
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a,b,m=0;
char s[2010],ss[2];
bool f;
int main()
{
scanf ("%d",&n);
for (int i=0;i<n;i++) {
scanf ("%s",ss);
s[i]=ss[0];
}
a=0;b=n-1;
while (a<=b) {
f=false;
for (int i=0;i+a<=b;i++) {
if (s[a+i]<s[b-i]) {
f=true;
break;
}
else if (s[a+i]>s[b-i]) {
f=false;
break;
}
}
if (f) {
putchar(s[a++]);
m++;
}
else {
putchar(s[b--]);
m++;
}
if (m%80==0) puts("");
}
return 0;
}
相关文章推荐
- POJ 3617 Best Cow Line (贪心)
- poj 3617 Best Cow Line(贪心)
- 【bzoj 1692】【bzoj 1640】【poj 3617】【poj 3623】Best Cow Line 好牛队 双倍经验水水水
- POJ 3617 Best Cow Line 贪心
- poj 3617 Best Cow Line(贪心)
- POJ-3617-Best Cow Line
- poj-【3617 Best Cow Line】
- POJ——3617 Best Cow Line
- POJ 3617 Best Cow Line
- poj 3617 Best Cow Line
- POJ-3617-Best Cow Line(贪心算法+Java)
- 【bzoj 1692】【bzoj 1640】【poj 3617】【poj 3623】Best Cow Line 好牛队 双倍经验水水水
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- POJ 3617 Best Cow Line
- poj 3617 Best Cow Line(简单贪心)
- POJ 3617 Best Cow Line (贪心)