代码:

#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
char input[2005]; int main()
{
int n;
int i,j;
while(scanf("%d",&n)!=EOF)
{
int lbit=0,rbit=n-1;//左边的位:lbit 右边的位:rbit
getchar();
for(i=0;i<=n-1;i++)
scanf("%c",&input[i]);
getchar(); while(lbit<=rbit)
{
bool cmpleft=false;//定义字典序比较的bool变量 如果左边小为true 右边小为false //左起字符串与右起字符串比较
for(i=0;lbit+i<rbit;i++)
{
if(input[lbit+i]<input[rbit-i])
{
cmpleft=true;
break;
}
else if(input[lbit+i]>input[rbit-i])
{
cmpleft=false;
break;
}
//如果相等continue
} if(cmpleft)putchar(input[lbit++]);//从左边取
else putchar(input[rbit--]);//从右边取
} printf("\n");
}
return 0;
}

贪心算法-Best cow line-字典序问题的更多相关文章

  1. 贪心算法训练(九)——Best Cow Line(字典序最小问题)

    原题链接:Best Cow Line 1. 问题描述 2. 输入 6 A C D B C B 3. 输出 ABCBCD 4.思路分析 不断地取原字符串 S 中开头和末尾比较小的字符串放到 T 的末尾 ...

  2. POJ 3617 Best Cow Line 字典序最小

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #inc ...

  3. POJ 3617:Best Cow Line(贪心,字典序)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30684   Accepted: 8185 De ...

  4. POJ 3617 Best Cow Line (字典序最小问题 & 贪心)

    原题链接:http://poj.org/problem?id=3617 问题梗概:给定长度为 的字符串 , 要构造一个长度为 的字符串 .起初, 是一个空串,随后反复进行下列任意操作. 从 的头部删除 ...

  5. poj 3617 Best Cow Line (字符串反转贪心算法)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 2826 Des ...

  6. POJ 3617 Best Cow Line 贪心算法

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26670   Accepted: 7226 De ...

  7. 编程算法 - 最好牛线(Best Cow Line) 代码(C)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012515223/article/details/37909933 最好牛线(Best Cow L ...

  8. poj3617 best cow line(贪心题)

    Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32687   Accepted: 8660 De ...

  9. POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心

    带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...

随机推荐

  1. Failed to load project at 'xxx.xcodeproj', incompatible project version。

    Failed to load project at 'xxx.xcodeproj', incompatible project version. 更新最新的xcode,xcode高版本可以打开低版本的 ...

  2. myeclipse连接并运行sql文件

    1:在工程目录上右键>new >SQL File  ,写入sql 2:在sql文件上面右键>execute sql files 3:选择数据库类型,并点击create创建一个连接: ...

  3. java maven项目找不到jconsole-1.8.0.jar和tools-1.8.0.jar包

    今天在整合jar包时候,出现了 这是我导入的jar坐标 <dependency> <groupId>com.alibaba</groupId> <artifa ...

  4. python图片处理(二)

    未经允许,请勿转载!!!! 这次打算先写处理图片的方法,然后再调用方法来运行 下面先写的是处理图片的方法: # -*- coding: utf-8 -*- import os import matpl ...

  5. iOS 设计模式-委托模式

    委托是指给一个对象提供机会对另一对象中的变化做出反应或者相应另一个对象的行为.其基本思想是协同解决问题. Delegate的使用场合 对象A内部发生了一些事情,想通知对象B 对象B想监听对象A内部发生 ...

  6. 关于Redis-存Long取Integer类型转换错误的问题;String对象被转义的问题

    背景 最近遇到了两个Redis相关的问题,趁着清明假期,梳理整理. 1.存入Long类型对象,在代码中使用Long类型接收,结果报类型转换错误. 2.String对象的反序列化问题,直接在Redis服 ...

  7. 使用i5ting_toc 预览 markdown 文件

    i5ting_toc__tree https://github.com/i5ting/i5ting_ztree_toc 是去哪儿网前段架构师狼叔编写的一个jQuery插件,用于将markdown 转化 ...

  8. Intro to Python for Data Science Learning 7 - 2D NumPy Arrays

    2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...

  9. EditPlus 5.1.2066 中文版(1月30日修正)

    之前有一些网友反馈汉化版的 EditPlus 中翻页键无法正常工作.经过调查,发现是翻译工具的问题. 因此,我用新的工具重新翻译了 EditPlus.翻页键在新中文版中应该可以正常工作了. 有需要的网 ...

  10. ActiveMQ 安装以及集群搭建

    安装环境: jdk1.7 apache-activemq-5.11.1-bin.tar.gz VM虚拟机redhat6.5-x64:192.168.1.200 Xshell4 部署方案: 主机IP 集 ...