当前位置:网站首页>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
边栏推荐
- Leetcode 30. 串联所有单词的子串
- Selenium advanced operations
- DaGAN论文解读
- 新一代垃圾回收器—ZGC
- 腾讯T2大牛亲自讲解,跳槽薪资翻倍
- Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
- String长度限制?
- golang的超时处理使用技巧
- Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
- Mysql Information Schema 学习(一)--通用表
猜你喜欢

PowerPivot——DAX(初识)

Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法

Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
In depth analysis, Android interview real problem analysis is popular all over the network

如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!

激进技术派 vs 项目保守派的微服务架构之争
![[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer](/img/8c/afb90128e7a523bbee4c6c4166363f.png)
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer

redisson bug分析

深度剖析原理,看完这一篇就够了

Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
随机推荐
PowerPivot——DAX(初识)
Introduction to enterprise lean management system
Interpretation of Dagan paper
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
[玩转Linux] [Docker] MySQL安装和配置
《数字经济全景白皮书》保险数字化篇 重磅发布
腾讯T3手把手教你,真的太香了
Configuration and simple usage of the EXE backdoor generation tool quasar
[play with Linux] [docker] MySQL installation and configuration
RT-Thread 组件 FinSH 使用时遇到的问题
社招面试心得,2022最新Android高频精选面试题分享
精彩编码 【进制转换】
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
leetcode先刷_Maximum Subarray
After solving 2961 user feedback, I made such a change
接雨水问题解析
Zero foundation entry polardb-x: build a highly available system and link the big data screen
句号压缩过滤器
121. The best time to buy and sell stocks
Selenium advanced operations