当前位置:网站首页>Poj3617 best cow line
Poj3617 best cow line
2022-07-06 19:50:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Although the question is simple , But it's very good , Because the process is very good . Comparison of development ideas And encourage people to , It's not like being greedy , Push the poor , But it's annoying
In view of the long N string S, And then the empty string STR. Whenever there are two choices 1: Delete S Add the first element of falsehood STR On 2: Delete S Add the last element STR On
Yes STR Dictionary order is the smallest And the output
At first, I may have no worries to think about Every comparison S The head and tail elements Take the smaller one and delete it if STR in . But if S If the head and tail elements are the same, this method will not work , Because it depends on the elements between them to take the head or tail first , At this time, it's better to come backwards or to follow ? Then it's better to compare the dictionary order between the straight one and the reverse one , So when the head and tail are equal, they can be included in the middle ,
practice :
character string S. Then invert to get S1, Compare the size if S Small , Then take S The head element of . if S If it's big, take S The tail element of , Then take it. S The horse . Compared with its inversion , Do it in such a cycle N You can do it next time
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
#include<cctype>
#define ll long long
#define LL __int64
#define eps 1e-8
#define inf 0xfffffff
//const LL INF = 1LL<<61;
using namespace std;
//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;
string s;
string str;
string ans;
string ch;
int main() {
int n;
bool flag = false;
while(cin>>n) {
while(n--) {
cin>>ch;
s += ch;
}
str = s;
reverse(s.begin(),s.end());
int len = s.length();
while(len--) {
if(str < s) {
ans += str[0];
str.erase(0,1);
}
else {
ans += str[str.length() - 1];
str.erase(str.length() - 1,1);
}
s = str;
reverse(s.begin(),s.end());
}
for(int i=0;i<ans.length();i++) {
cout<<ans[i];
if((i+1)%80 == 0)puts("");
}
puts("");
}
return 0;
}Copyright notice : This article is an original blog article , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117137.html Link to the original text :https://javaforall.cn
边栏推荐
- 从sparse.csc.csr_matrix生成邻接矩阵
- 系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
- Microservice architecture debate between radical technologists vs Project conservatives
- 学习探索-使用伪元素清除浮动元素造成的高度坍塌
- Alibaba数据源Druid可视化监控配置
- String长度限制?
- POJ 3207 Ikki&#39;s Story IV – Panda&#39;s Trick (2-SAT)
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- [translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
- 终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
猜你喜欢

接雨水问题解析

MySQL information schema learning (I) -- general table

Spark foundation -scala

语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech

How to access localhost:8000 by mobile phone

【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)

PowerPivot——DAX(初识)

Li Kou 101: symmetric binary tree

Tencent Android interview must ask, 10 years of Android development experience

【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
随机推荐
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Tensorflow2.0 自定义训练的方式求解函数系数
Example of applying fonts to flutter
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
范式的数据库具体解释
CF960G - Bandit Blues(第一类斯特林数+OGF)
Interview assault 63: how to remove duplication in MySQL?
A5000 vGPU显示模式切换
学习打卡web
腾讯安卓开发面试,android开发的基础知识
凤凰架构3——事务处理
句号压缩过滤器
Alibaba data source Druid visual monitoring configuration
Recursive implementation of department tree
《数字经济全景白皮书》保险数字化篇 重磅发布
Using clip path to draw irregular graphics
在解决了 2961 个用户反馈后,我做出了这样的改变...
信息系统项目管理师---第八章 项目质量管理
从sparse.csc.csr_matrix生成邻接矩阵