当前位置:网站首页>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
边栏推荐
- Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
- Leetcode 30. 串联所有单词的子串
- POJ3617 Best Cow Line 馋
- 转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
- 理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
- 腾讯T4架构师,android面试基础
- Example of shutter text component
- 腾讯云数据库公有云市场稳居TOP 2!
- Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
- Recursive implementation of department tree
猜你喜欢
腾讯T4架构师,android面试基础
Hudi vs Delta vs Iceberg
Druid database connection pool details
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
信息系统项目管理师---第八章 项目质量管理
Cesium 点击绘制圆形(动态绘制圆形)
DaGAN论文解读
腾讯T2大牛亲自讲解,跳槽薪资翻倍
Phoenix Architecture 3 - transaction processing
激进技术派 vs 项目保守派的微服务架构之争
随机推荐
Mysql Information Schema 學習(一)--通用錶
Cesium 两点之间的直线距离
腾讯T2大牛亲自讲解,跳槽薪资翻倍
Example of applying fonts to flutter
mod_wsgi + pymssql通路SQL Server座
接雨水问题解析
HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
企业精益管理体系介绍
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
Logstash expressway entrance
Unbalance balance (dynamic programming, DP)
Standardized QCI characteristics
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
新一代垃圾回收器—ZGC
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
Introduction to enterprise lean management system
(3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
About image reading and processing, etc
《数字经济全景白皮书》保险数字化篇 重磅发布
部门树递归实现