poj For Short

本文介绍了一种将英文句子转化为首字母缩写的算法,并提供了完整的C++实现代码。该算法遵循特定规则,如只保留字母组成的单词的首字母并转换为大写,删除空格等。
/*E:For Short

    查看
    提交
    统计
    提问

总时间限制:
    1000ms
内存限制:
    65536kB

描述

    Have you ever been annoyed when someone uses incomprehensible abbreviations, such as AFAIK, ASAP, FYI, GTSY, IYKWIM, KIT, LOL, LTNS, PM, PS, SYS, TA, WB? Are you always trying hard to understand them? Now it is time for striking back!

    Even more, you are going to shorten the whole sentences instead of phrases. For example, the previous sentence can be "EM,YAGTSTWSIOP." for short. Thus, you are able to shout proudly: "Ha-ha, can anyone understand me? Do not speak abbreviations to me anymore, or I will use these sentences against you!"

    As a man of principle, you decide to apply these rules during sentences shortening:

        A sentence is a line contains printable characters (From ASCII codes 32 to 126) only, including letters, digits, and punctuation marks and so on.

        A word is a substring of sentence which only consists of letters, and any characters adjacent to the word are not letters.

        A word is replaced by the uppercase of the beginning letter of it for short.

        Other characters except spaces are remained. Spaces are deleted.

    Now you are trying to rewrite these given sentences for short.
输入
    The first line contains an integer T (1 ≤ T ≤ 20) -- the number of test cases.

    Each test case contains a legal sentence in a single line. The length of a sentence is less than 1000 characters.
输出
    For each test case, output only one line -- the corresponding "sentence" after shortened.
样例输入

    1
    Even more, you are going to shorten the whole sentences instead of phrases.

样例输出

    EM,YAGTSTWSIOP.*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
using namespace std;
int main()
{
    int t = 0;
    //cin >> t;
    scanf("%d", &t);
    getchar();
    for(int i = 0; i < t; i++)
    {
        char ch[1005];
        char b[1005];
        gets(ch);
        int bj = 0;
        for(int j = 0; j < strlen(ch); j++)
        {
            if(ch[j] >= 'a' && ch[j] <= 'z')
            ch[j] += 'A' - 'a';
        }
        int mark = 1;
        for(int j = 0; j < strlen(ch); j++)
        {
            if(ch[j] != ' ' && (ch[j]<'A' || ch[j] > 'Z')) {b[bj] = ch[j];mark = 1;bj++;continue;}
            if(mark&&ch[j] != ' ') {b[bj] = ch[j]; mark = 0;bj++;continue;}
            if(ch[j] == ' ') {mark = 1; continue;}
        }
    for(int j = 0; j < bj ; j++)
    //cout << b[j];
    printf("%c" ,b[j]);
    printf("\n");
    }
    return 0;
}

转载于:https://my.oschina.net/locusxt/blog/133405

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值