问题标题: 酷町堂:2237为什么60分

0
0
已解决
金一铭
金一铭
新手光能
新手光能

2237错误60分代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size())
    {
        cout<<b<<a<<endl;
        cout<<b<<endl;
    }
    if(a.size()<b.size())
    {
        cout<<a<<b<<endl;
        cout<<a<<endl;
    }
    cout<<a.size()+b.size();
    return 0;

}

谁能帮我找错?


0
已采纳
傅文彬
傅文彬
新手天翼
新手天翼

建议将

if(a.size()<b.size())

{

cout<<a<<b<<endl;

cout<<a<<endl;

}

改成:

else

{

cout<<a<<b<<endl;

cout<<a<<endl;

}

因为如果两个字符串相等怎么办,按着你的代码就直接输出cout<<a.size()+b.size();,这样不对,Yes sir?

0
祝明朗
祝明朗
初级光能
初级光能


   字符串 a,b,c,d;
    整形 l;
    getline(cin,a);
    getline(cin,b);
    如果(a>b)
    {
        c=a+b;
        d=a;
    }
    否则
    {
        c=b+a;
        d=b;
    }
    l=c.size();
    输出<<c<<endl<<d<<endl<<l;

记得加头文件

要不然就用万能头

0
我要回答