当前位置:网站首页>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
边栏推荐
- PHP与EXCEL PHPExcel
- HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
- beegfs高可用模式探讨
- Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
- 【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
- 如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
- 350. 两个数组的交集 II
- 句号压缩过滤器
- 激进技术派 vs 项目保守派的微服务架构之争
- [translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
猜你喜欢
Low CPU load and high loadavg processing method
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Phoenix Architecture 3 - transaction processing
Cesium 点击绘制圆形(动态绘制圆形)
Interpretation of Dagan paper
Using clip path to draw irregular graphics
某东短信登录复活 安装部署教程
Hudi vs Delta vs Iceberg
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
MySQL information Schema Learning (i) - - General table
随机推荐
MySQL information schema learning (I) -- general table
腾讯T4架构师,android面试基础
学习探索-无缝轮播图
算法面试经典100题,Android程序员最新职业规划
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
[translation] supply chain security project in toto moved to CNCF incubator
Mysql Information Schema 学习(二)--Innodb表
How to do smoke test
Learning and Exploration - Seamless rotation map
After solving 2961 user feedback, I made such a change
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Lick the dog until the last one has nothing (simple DP)
激进技术派 vs 项目保守派的微服务架构之争
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
121. 买卖股票的最佳时机
The slave i/o thread stops because master and slave have equal MySQL serv
利用 clip-path 绘制不规则的图形
LeetCode_ Double pointer_ Medium_ 61. rotating linked list
MySql必知必会学习
Transformer model (pytorch code explanation)