BestCoder Round#15 1001-Love

本文提供了一个编程实例,通过解析输入的男性和女性名字,自动生成符合特定文化习俗的爱子名字。代码简洁高效,适用于理解字符串处理和格式化的基本概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://acm.hdu.edu.cn/showproblem.php?pid=5082

 

Love

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 64    Accepted Submission(s): 51


Problem Description
There is a Love country with many couples of Darby and Joan in it. In order to commemorate their love, they will do some thing special when giving name to their offspring. 
When a couple want to give name to their offspring, they will firstly get their first names, and list the one of the male before the one of the female. Then insert the string “small” between their first names. Thus a new name is generated. For example, the first name of male is Green, while the first name of the female is Blue, then the name of their offspring is Green small Blue.
You are expected to write a program when given the name of a couple, output the name of their offsping.
 

Input
Multi test cases (about 10), every case contains two lines. 
The first line lists the name of the male.
The second line lists the name of the female.
In each line the format of the name is [given name]_[first name].
Please process to the end of file.

[Technical Specification]
 the length of the name   20
[given name] only contains alphabet characters and should not be empty, as well as [first name].
 

Output
For each case, output their offspring’s name in a single line in the format [first name of male]_small_[first name of female].
 

Sample Input

  
Jim_Green Alan_Blue
 

Sample Output

  
Green_small_Blue
 

Source
 

 解题思路:题目已经告诉你怎么输出答案了0.0 -》 the format [first name of male]_small_[first name of female]. 

 1 #include <stdio.h>
 2 #include < string.h>
 3 
 4  int main(){
 5      char str1[ 50], str2[ 50], str3[ 50], str4[ 50];
 6      int len, i, j;
 7      while(scanf( " %s %s ", str1, str2) != EOF){
 8         len = strlen(str1);
 9          for(i =  0; i < len; i++){
10              if(str1[i] ==  ' _ '){
11                  break;
12             }
13         }
14         i++;
15          for(j = i; j < len; j++){
16             str3[j - i] = str1[j];
17         }
18         str3[j - i] =  ' \0 ';
19 
20         len = strlen(str2);
21          for(i =  0; i < len; i++){
22              if(str2[i] ==  ' _ '){
23                  break;
24             }
25         }
26         i++;
27          for(j = i; j < len; j++){
28             str4[j - i] = str2[j];
29         }
30         str4[j - i] =  ' \0 ';
31         printf( " %s_small_%s\n ", str3, str4);
32     }
33      return  0;

34 } 

 

转载于:https://www.cnblogs.com/angle-qqs/p/4051143.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值