题目描述:
将给定的字符串连接起来。书中的算法描述如下:
图:字符串连接算法
分析:因为C++具有字符串类型(string),两个字符串拼接,只需用“+”连接,所有该题利用C++更为简便。
输入
三对字符串,每对字符串占一行,用空格隔开。每个字符串只包含数字和英文字母大小写且长度不超过100。输出
将后一个字符串连接到前一个字符串后面,如果结果字符串长度超过100,输出一行“Result String is cutted.”否则将结果字符串输出来。样例输入
hello dotcpp
123 456
doyour best
样例输出
hellodotcpp
123456
doyourbest
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n=3;
string s1,s2,temp;
while(n--)
{
cin>>s1>>s2;
temp=s1+s2;
if(temp.size()>100)
cout<<"Result String is cutted."<<endl;
else
cout<<temp<<endl;
}
}