九度-题目1206:字符串连接

http://ac.jobdu.com/problem.php?pid=1206
题目描述:

不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

输入:

每一行包括两个字符串,长度不超过100。

输出:

可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。

样例输入:
abc def
样例输出:
abcdef
来源:
2010年华中科技大学计算机保研机试真题

直接使用string,会比char[]方便一些。

 1 #include <iostream>
 2 #include <string.h>
 3 #include <string>
 4 
 5 using namespace std;
 6 
 7 string str1, str2;
 8 
 9 int main()
10 {
11     string ans;
12     while(cin>>str1, cin>>str2)
13     {
14         ans=str1+str2;
15         cout << ans <<endl;
16     }
17     return 0;
18 }

 

posted @ 2017-04-24 10:40  悟空的爸爸  阅读(334)  评论(0编辑  收藏  举报