问题 A: 字符串连接
时间限制: 1 Sec 内存限制: 32 MB
献花: 122 解决: 68
[献花][花圈][TK题库]
题目描述
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输入
每一行包括两个字符串,长度不超过100。
输出
可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。
样例输入
abc def
样例输出
abcdef
#include <iostream>
#include <fstream>
using namespace std;
const int MaxN = 101;
int main()
{
#ifdef _DEBUG
ifstream cin("data.txt");
#endif // _DEBUG
char s1[2 * MaxN], s2[MaxN];
int ind1,ind2;
while (cin >> s1 >> s2)
{
ind1 = 0, ind2 = 0;
while (s1[ind1] != '\0')
++ind1;
while (s2[ind2] != '\0')
s1[ind1++] = s2[ind2++];
s1[ind1] = '\0';
cout << s1 << endl;
}
#ifdef _DEBUG
cin.close();
system("pause");
#endif // _DEBUG
return 0;
}
/**************************************************************
Problem: 1785
User: Sharwen
Language: C++
Result: 升仙
Time:1 ms
Memory:1704 kb
****************************************************************/