POJ 3617 Best Cow Line(字典序)
来源:互联网 发布:mac系统打符号 编辑:程序博客网 时间:2024/05/21 10:34
题目:
http://poj.org/problem?id=3617
题解:
1.按照字典序比较S和将S反转后的字符串S‘。
2.如果S较小,就从S的开头取出一个文字,追加到T的末尾。
3.如果S’较小,就从S的末尾取出一个文字,追加到T的末尾。
(来自《挑战程序设计竞赛》)
看了书,写不出比书中更好的题解了。
一样,代码要自己敲。
代码:
#include<stdio.h>int a[2000];void f(int n){int s=0;int e=n-1;int sum=0;while(s<=e){int left=1;for(int i=0;s+i<=e;i++){if(a[s+i]>a[e-i]){left=0;break;}if(a[s+i]<a[e-i]){left=1;break;}}if(left) printf("%c",a[s++]);else printf("%c",a[e--]);sum++;if(sum%80==0) printf("\n");//题目输出格式的要求}}int main(){int n;while(~scanf("%d",&n)){for(int i=0;i<n;i++){getchar();scanf("%c",&a[i]);}f(n);printf("\n");}return 0;}
0 0
- 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 No.3617-Best Cow Line(字典序最小问题)
- poj 3617 Best Cow Line(取字典序最小的一种排序)
- POJ NO.3617 Best Cow Line(字典序最小问题)
- POJ 3617Best 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(贪心)
- new blog
- coursera-android-week4-3 layout menus and action bar
- [WebKit]管好页面缓存
- 【递推】【DP】-HDU-2175-汉诺塔⑨
- android xml异常:Attribute is missing the Android namespace prefix
- POJ 3617 Best Cow Line(字典序)
- android 关于底部控件遮挡上面list控件的解决办法
- hdu3183 RMQ模板 复杂度O(nlogn)
- 解读AtomicStampedReference的源码
- 内联函数与宏的比较
- 语言的歧义
- 内存管理寄存器
- apktool反编译资源时出现CastException的一则解决方法
- C语言知识点