poj For Short

/*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;
}

你可能感兴趣的:(ACM,poj,cpp)