poj3617 Best Cow Line
来源:互联网 发布:嘉贝逸飞淘宝网站 编辑:程序博客网 时间:2024/06/01 09:49
写在前边:暑假开始了,白书刷起来
题目大意:给你字符串和相应的规则,求解出最长的字符串。
题目思路:贪心,坑点:设计贪心思路的时候要考虑首尾一样时的策略与方法。
代码:
#include<iostream>#include<cstdio>using namespace std;int n;char str[2020];void func(){ int l=0,r=n-1,cnt=0; while(l<=r) { int flag=0; for(int i=0;i+l<=r;i++) { if(str[i+l]<str[r-i]) { flag=1; break; } else if(str[i+l]>str[r-i]) { flag=0; break; } } if(flag) cout<<str[l++]; else cout<<str[r--]; cnt++; if(cnt==80) { cout<<endl; cnt=0; } }}int main(){ while(~scanf("%d",&n)) { for(int i=0;i<n;i++) cin>>str[i]; func(); }}
阅读全文
0 0
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- best cow line(poj3617)
- POJ3617-Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- poj3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617-Best Cow Line
- poj3617 Best Cow Line
- poj3617 Best Cow Line
- POJ3617 Best Cow Line
- POJ3617 Best Cow Line
- poj3617 Best Cow Line 贪心
- POJ3617 Best Cow Line 贪心
- poj3617 Best Cow Line 贪心
- poj3617 Best Cow Line 贪心
- Python3之 切片之逆向截取
- java工具类数字金额转中文大写
- 互联网协议(Internet Protocol Suite)的基础知识笔记
- 02. 无权图的建模和相关算法
- 决策树ID3算法python实现代码及详细注释
- poj3617 Best Cow Line
- springmvc 处理Date类型
- -设计一个类不能被继承 2.设计一个类只能在堆上创建对象。 3.设计一个类只能在栈上创建对象。
- centos7下glusterFs 分布式文件系统环境搭建
- JS解析json数据并将json字符串转化为数组的实现方法
- 03. 加权图的建模和相关算法
- jdk安装 path配置 tomcat安装
- linux下创建用户和添加用户权限
- 浅析OpenNI2---Driver开发(2)