高质量题解|A441.字符串判定
2026-02-19 11:44:14
发布于:河北
1阅读
0回复
0点赞
解题思路
先判断两个字符串 a 和 b 的长度是否相同,获取字符串长度用 .size()
如果 a > b ,那么 a 的长度大,先输出 b 后输出 a ;b > a 则相反
如果长度不一样,那么判断 a > b 还是 b > a ,大致思路与判断字符串长度差不多
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
string a,b;
cin >> a >> b;
if(a.size() != b.size()){
if(a.size() > b.size()){
cout << b << endl;
cout << a << endl;
}else{
cout << a << endl;
cout << b << endl;
}
}else{
if(a > b){
cout << b << endl;
cout << a << endl;
}else{
cout << a << endl;
cout << b << endl;
}
}
return 0;
}
这里空空如也








有帮助,赞一个