POJ 3617 Best Cow Line——贪心
来源:互联网 发布:云计算运维工程师待遇 编辑:程序博客网 时间:2024/06/05 20:26
注意80个字符换行
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int main() { int n; char str[10000], ans[10000]; scanf("%d", &n); for (int i = 0; i < n; i++) { getchar(); scanf("%c", &str[i]); } int L = 0, R = n - 1, cnt = 0; while (L <= R) { if (str[L] < str[R]) { ans[cnt++] = str[L]; L++; } else if (str[L] > str[R]) { ans[cnt++] = str[R]; R--; } else { int tl = L, tr = R; while (tl <= tr && str[tl] == str[tr]) { tl++; tr--; } if (tl <= tr) { if (str[tl] < str[tr]) { ans[cnt++] = str[L]; L++; } else if (str[tl] > str[tr]) { ans[cnt++] = str[R]; R--; } } else { ans[cnt++] = str[L]; L++; } } } for (int i = 0; i < n; i++) { printf("%c", ans[i]); if ((i + 1) % 80 == 0) printf("\n"); }}
阅读全文
1 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 3617 Best Cow Line 贪心
- POJ 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 【贪心】
- POJ 3617 Best Cow Line(贪心)
- 欢迎使用CSDN-markdown编辑器
- 1002
- 学习SpringMVC——从HelloWorld开始
- H5面试题---&&的使用
- Windows下免安装版Tomcat的配置
- POJ 3617 Best Cow Line——贪心
- TKPHP5软删除
- 树莓派LED驱动编写
- Lambda表达式树
- KNN算法初步实现
- Win10下搭建Clion+OpenCV3.2+OpenCV_Contrib3.2的环境
- maven笔记(三)
- 求一个无序数组的中位数
- 最新spring boot搭建,整合jsp页面以及打war包配置