当前位置:网站首页>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
边栏推荐
猜你喜欢
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
Transformer model (pytorch code explanation)
In depth analysis, Android interview real problem analysis is popular all over the network
Mysql Information Schema 学习(二)--Innodb表
Hudi vs Delta vs Iceberg
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
算法面试经典100题,Android程序员最新职业规划
Leetcode 30. 串联所有单词的子串
ZABBIX proxy server and ZABBIX SNMP monitoring
随机推荐
Lick the dog until the last one has nothing (simple DP)
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
LeetCode_双指针_中等_61. 旋转链表
MySQL information schema learning (I) -- general table
RT-Thread 组件 FinSH 使用时遇到的问题
Phoenix Architecture 3 - transaction processing
Recursive implementation of department tree
beegfs高可用模式探讨
新一代垃圾回收器—ZGC
【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
POJ 3207 Ikki&#39;s Story IV – Panda&#39;s Trick (2-SAT)
Interview assault 63: how to remove duplication in MySQL?
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
小微企业难做账?智能代账小工具快用起来
Leetcode brush first_ Maximum Subarray
数据的同步为每个站点创建触发器同步表
Alibaba数据源Druid可视化监控配置
AddressSanitizer 技术初体验