0%

六学家的困惑

链接:https://ac.nowcoder.com/acm/contest/625/C
来源:牛客网

题意:给你两个数串,只能从两个数串的头和尾取数,然后请你输出这两个数串能组成的最大的数串….
一道水题,当时并没有做出来,很难受,而且当时思路很模糊,是记录数串下标来输出,结果测试用例对了,但是不能AC,不知道哪里错了,看了别人的代码后,恍然大悟,痛感自己实力不足!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main(){
//ios::sync_with_stdio(false);
int T,cnt=0;
string s[4];
cin>>T;
while(T--){
cin>>s[0]>>s[2];
s[1] = s[0];
s[3] = s[2];
reverse(s[1].begin(),s[1].end());
reverse(s[3].begin(),s[3].end());
int n = s[0].size()+s[2].size();
string ans;
while(n--){
int id =0;
for(int i=0;i<=3;i++)
if(s[i]>s[id]) id = i;
ans+=s[id][0];
s[id].erase(s[id].begin());
s[id^1].erase(s[id^1].end()-1);
}
printf("Case #%d: ",++cnt);
cout<<ans<<endl;
}

return 0;
}

在字符串上面吃了好多次亏了,不行,我要准备写一篇关于字符串的blog才行,不能再在这上面吃亏了!!!

-------------本文结束感谢您的阅读-------------