您的位置:首页 > 其它

HDU 5082 Love

2015-08-21 10:30 417 查看


Love

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 763 Accepted Submission(s): 455



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]

3 ≤ 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

BestCoder Round #15



Recommend

heyang | We have carefully selected several similar problems for you: 5416 5415 5414 5413 5412

纯属字符串水题!!!

题目意思很简单,给出父母的名字,帮孩子取名字。

简化一下就是:孩子的名字=[父亲的frist name]_small_[母亲的frist name];

然后再输出孩子的名字就可以了。

//AC: 15MS 1712K

#include<cstring>
#include<cstdio>
char fa[50],mo[50];
int main() {
    while(~scanf("%s%s",fa,mo)) {
        int sign;
        int la=strlen(fa);
        int lb=strlen(mo);
        for(int i=0; i<la; i++) {
            if(fa[i]>='A' && fa[i]<='Z' || fa[i]>='a' && fa[i]<='z')
                continue;
            else{
                sign=i;
                break;
            }
        }
        printf("%s%c",fa+sign+1,fa[sign]);
        printf("small");
        for(int i=0; i<lb; i++){
            if(mo[i]>='A' && mo[i]<='Z' || mo[i]>='a' && mo[i]<='z')
                continue;
            else {
                sign=i;
                break;
            }
        }
        printf("%s\n",mo+sign);
    }
    return 0;
}


以上为练习赛时的代码,事后想想发现还可以更简短:

//AC: 0MS 1708K

#include<cstring>
#include<cstdio>
char fa[50],mo[50];
int main() {
    while(~scanf("%s",fa)){
        int la = 0,lb = 0;
        while(fa[la++] != '_');
        if(!~scanf("%s",mo))
            break;
        while(mo[lb++] != '_');
        printf("%s_small_%s\n",fa+la,mo+lb);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: