问题标题: 酷町堂:2811 字符串拷贝1 HELP ! ! ! HELP ! ! !

0
0
已解决
黄品翔
黄品翔
初级光能
初级光能

题目描述 Description

输入两个字符串,长度不超过100,如果第二个字符串的长度大于第一个字符串的长度的话将字符串2拷贝到字符串1中,否则将字符串1拷贝到字符串2中,再将字符串2的前n个字符串连接到字符串1后面,最后输出字符串1的结果

输入描述 Input Description

第一行:一个数字n
第二行:第一个字符串
第三行:第二个字符串,输入保证两个字符串的长度都>=n

输出描述 Output Description

输出字符串1

样例输入 Sample Input

 

3
TVxQacTjfjvaO
OSqbVgKOMTdhF

样例输出 Sample Output

 

TVxQacTjfjvaOTVx

0分代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    char a[101],b[101];
    cin>>n;
    gets(a);
    gets(b);
    int c=strlen(a),d=strlen(b);
    for(int i=n;i<c;i++)
    {
        for(int j=n;j<d;j++)
        {
            if(a[i]>=b[j])
            {
                a[i]=b[i];
                cout<<b[i]<<" ";
            }
            else
            {
                cout<<b[j]<<" "<<a[i]<<" "<<b[n]<<" ";
            }
        }
    }
    return 0;
}

请各位大佬帮忙找错    !!(2)    !!!!!!!!(8)    !(1)    !(1)

感谢!!!

黄品翔在2019-03-15 17:33:58追加了内容

题目:

2811 字符串拷贝1

黄品翔在2019-03-15 17:34:11追加了内容

题目:

2811 字符串拷贝1

黄品翔在2019-03-15 17:34:53追加了内容

手滑了~~~

黄品翔在2019-03-16 10:59:16追加了内容

这道题我已经做出来了,再问个问题。

1164   比较字符串大小

题目如下:

题目描述 Description

输入两个数字字符串,将其转换为数值后,再比较它们的大小。

输入描述 Input Description

输入两行,第一行为数字字符串A,第二行为数字字符串B。(字符串长度小于10)

输出描述 Output Description

输出较大的数值。

样例输入 Sample Input

 

1234
234

样例输出 Sample Output

 

1234

 

50分错误代码:

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

好像有个函数叫 atoi ,可以把字符串转换为数值,但我不会用啊!!!

啊!!!啊!!!啊!!!


0
0
0
我要回答