串结构练习——字符串连接

题目描述

 给定两个字符串string1和string2,将字符串string2连接在string1的后面,并将连接后的字符串输出。
连接后字符串长度不超过110。 

输入

 输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2。
 

输出

 对于每组输入数据,对应输出连接后的字符串,每组输出占一行。
 

示例输入

123
654
abs
sfg

示例输出

123654
abssfg

#include<iostream>
#include<cstring>
using namespace std;
void concat(char t[],char str1[],char str2[])
{
    int j=0,k=0;
    while(str1[j]!='\0') t[k++]=str1[j++];
    j=0;
    while(str2[j]!='\0') t[k++]=str2[j++];
    t[k]='\0';
}
int main()
{
    char t[220],str1[110],str2[110];
    while(cin>>str1)
    {
        cin>>str2;
        concat(t,str1,str2);
        for(int i=0;t[i]!='\0';i++)
            cout<<t[i];
        cout<<endl;
    }
    return 0;
}


### 关于 Python 中字典和字符串练习题与教程 #### 字典基础操作练习 在 Python 中,字典是一种非常灵活的数据结构,允许存储键值对。下面是一些针对字典的基础练习: 1. 创建一个新的字典 `my_dict` 并初始化它包含三个键值对:"name": "Alice", "age": 25, 和 "city": "Beijing"[^1]。 ```python my_dict = {"name": "Alice", "age": 25, "city": "Beijing"} print(my_dict) ``` 2. 访问并打印出字典中的 `"name"` 键对应的值[^2]。 ```python print(my_dict["name"]) ``` 3. 更新字典中 `"age"` 的值为 26。 ```python my_dict["age"] = 26 print(my_dict) ``` 4. 添加新的键值对到字典里,比如 `"country": "China"`。 ```python my_dict["country"] = "China" print(my_dict) ``` 5. 删除字典里的某个项,例如移除 `"city"` 这个条目。 ```python del my_dict["city"] print(my_dict) ``` #### 字符串基本操作练习 对于字符串而言,在 Python 中可以执行多种多样的操作来满足不同的需求。这里给出几个简单的例子作为入门级练习: 1. 定义一个变量 `greeting` 赋予其值 `"Hello, world!"`,然后将其转换成全部大写字母形式显示出来。 ```python greeting = "Hello, world!" print(greeting.upper()) ``` 2. 使用字符串的方法统计单词数量,假设有一个句子 stored_sentence = 'Python is an easy to learn powerful programming language.' ,计算其中有多少个单词。 ```python stored_sentence = 'Python is an easy to learn powerful programming language.' word_count = len(stored_sentence.split()) print(f"The sentence contains {word_count} words.") ``` 3. 将两个字符串连接起来形成一个新的字符串。 ```python first_part = "Good morning," second_part = " have a nice day." message = first_part + second_part print(message) ``` 这些只是初步接触 Python 字典和字符串的方式之一,更多高级特性和技巧可以在实际项目开发过程中逐步学习掌握。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值