题解 | #字符游戏#
字符游戏
https://www.nowcoder.com/practice/381e9c03e6b44c058d81d41f5da8386d
#include <iostream> using namespace std; //逆天题解,看20行,测试用例应该有相同字符,而且答案是根据官方题解得出的。。。。 //我就说看了半天没感觉哪里和官方题解不一样但是就是过不了,一口老血 int main() { ios::sync_with_stdio(0); // 标准输入流! string A,B; getline(cin,A); getline(cin,B); bool AC = true; bool BC = true; int LA = 0,RA = A.length()-1,LB = 0,RB = B.length()-1; string c; char Anum,Bnum; while(LA<=RA && LB<=RB) { Anum = AC?A[LA]:A[RA]; Bnum = BC?B[LB]:B[RB]; //cout<<"::"<<A[Anum]<<" "<<B[Bnum]<<endl; if(Anum>=Bnum)//题有误,按理说Anum不可能等于Bnum,但此处去掉等号会过不了 { c.push_back(Bnum); if(BC) { BC = !BC; ++LB; } else { BC = !BC; --RB; } } else { c.push_back(Anum); if(AC) { AC = !AC; ++LA; } else { AC = !AC; --RA; } } } while(LA<=RA) { Anum = AC?A[LA]:A[RA]; c.push_back(Anum); if(AC) { AC = !AC; ++LA; } else { AC = !AC; --RA; } } while(LB<=RB) { Bnum = BC?B[LB]:B[RB]; c.push_back(Bnum); if(BC) { BC = !BC; ++LB; } else { BC = !BC; --RB; } } cout<<c<<endl; return 0; } // 64 位输出请用 printf("%lld")