1986-指定位置插入单词

xiaoxiao2021-02-28  60

【C系列5.1】指针专题之爱的誓言 1986

Time Limit:  1 s      Memory Limit:   32 MB Submission:206     AC:84     Score:17.74 Submit  Status

Description

在好友们接连生完猴子后,Alex终于也遇到了她生命中的白马王子——Sherlock,他们各自写了一个代表爱的单词,然后Alex在Sherlock的单词的某个位置插入自己的单词作为二人爱的誓言。比如Alex的单词为water(s1),Sherlock的单词为flower(s2),Alex想要插入的位置为2,则最终爱的誓言为flwaterower(s3)。现在Alex希望已经陪着她解决了那么多道指针题目的你可以再帮助她一次。

Input

输入有多组。

每一组输入包含两个单词s1和s2,和一个大于0的整数N。s1、s2分别代表Alex和Sherlock的单词,N代表Alex要插入的位置。s1、s2的长度小于100.

Output

拼接后的爱的誓言s3。

Samples

input: water flower 2 output: flwaterower 下附AC代码: #include<stdio.h> #include<string.h> int main() { char str1[100]; char str2[100]; char *p1, *p2; int f, i; while (scanf("%s", str1) != EOF) { scanf("%s", str2); scanf("%d", &f); p1 = str1; p2 = str2; for (i = 0; i < f; i++) printf("%c", *(p2 + i)); for (i = 0; i < strlen(str1); i++) printf("%c", *(p1 + i)); for (i = f; i < strlen(str2); i++) printf("%c", *(p2 + i)); printf("\n"); } return 0; } 原题链接: http://acm.hznu.edu.cn/OJ/problem.php?cid=1092&pid=19
转载请注明原文地址: https://www.6miu.com/read-77737.html

最新回复(0)