7-5 30056 字符串连接 (15 分)
从键盘输入俩个字符串a和b,要求不用库函数strcat把b的前五个字符连接到a中;如果b的长度小于5,则把b中的所有元素都连接到a中。
输入格式:
输入两个字符串a,b。
输出格式:
b的前5个元素连接到a后的字符串。
输入样例:
abcdefg
1234567
输出样例:
abcdefg12345
输入样例:
zyxw
9876
输出样例:
zyxw9876
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
string s1,s2;
cin>>s1>>s2;
string str1 = "", str2 = "";
str1 = s1;
if(s2.length()<5){
str2 = s2;
}
else{
str2 = s2.substr(0,5);
}
cout<<str1+str2<<endl;
return 0;
}