列表

详情


WY56. 缩写

描述

在英文中,我们会把一些长的名字或者短语进行缩写。例如"looks good to me"缩写为"lgtm",短语中的每个单词的首字母组成缩写。现在给出一个字符串s,字符串s中包括一个或者多个单词,单词之间以空格分割,请输出这个字符串的缩写。

输入描述

输入包括一个字符串s,字符串长度length(1 ≤ length ≤ 50),字符串中只包括小写字母('a'~'z')和空格。

输出描述

输出一个字符串,即缩写的结果。

示例1

输入:

looks good to me

输出:

lgtm

原站题解

C 解法, 执行用时: 1ms, 内存消耗: 340KB, 提交时间: 2021-09-14

#include<stdio.h>
#include<string.h>

int main()
{
    char c[51];
    char res[50];
    int k=0;
    while(scanf("%s",c) != EOF)
    {
        res[k++] = c[0];
    }
    res[k] = '\0';
    printf("%s",res);
    return 0;
}

C 解法, 执行用时: 1ms, 内存消耗: 368KB, 提交时间: 2020-08-06

#include <stdio.h>
#include <string.h>
int main()
{
    char s[100];
    gets(s);
    int len=strlen(s);
    printf("%c",s[0]);
    for(int i=1;i<len;i++)
    {
    	if(s[i]==' ')
    	{
    		printf("%c",s[i+1]);
		}
	}
}

上一题