URAL 1601. AntiCAPS (strings)

1601. AntiCAPS

Time limit: 0.5 second

Memory limit: 64 MB

The blonde Angela has a new whim: internet chats. Of course, as any blonde, shewrites her messages using the upper case. You are the moderator of Angela‘sfavorite chat and you‘re fed up with her upper-case messages. The problemis
that Angela does not respond to your warnings. You decided to write a simpleantiCAPS corrector, which would make Angela‘s messages readable.

The correction rules are very simple:

  1. Sentences in a message consist of words, spaces and punctuation marks.
  2. Words consist of English letters.
  3. Sentences end with a full stop, exclamation mark, or question mark.
  4. The first word of each sentence must start with a capital letter, and all otherletters of the sentence must be lowercase.

Input

You are given Angela‘s message, which consists of uppercase English letters,spaces, line breaks and punctuation marks: full stops, commas, dashes, colons, exclamationand question marks. Total length of message is not exceeding
10000 symbols.

Output

Output the corrected message.

Sample

input output
HI THERE!
HOW DID YOU KNOW I AM A BLONDE?
Hi there!
How did you know i am a blonde?

Problem Author: Denis Musin

Problem Source: IX USU Open Personal Contest (March 1, 2008)

解析:注意两点:

1.每一个句子以‘.’,‘?’和‘!’结尾。每一个句子开头字符都要换成大写。

2.换行不算句子结尾的标志。

下面提供两组測试例子:

input1:

HELLO. I AM ANJELA! AND YOU?

I AM BLONDE.

output1:

Hello. I am anjela! And you?

I am blonde.

input2:

HHHHHHHHHH? SDSDFSDF! SFSDF. SDFAF

HKLLKSDJOI

output2:

Hhhhhhhhhh? Sdsdfsdf! Sfsdf. Sdfaf

hkllksdjoi

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif // sxk

    string s;
    int flag = 1;
    while(getline(cin, s)){
        int n = s.size();
        for(int i=0; i<n; i++){
            if(flag){
                if(s[i] >= ‘A‘ && s[i] <= ‘Z‘) flag = 0;
            }
            else{
                if(s[i] >= ‘A‘ && s[i] <= ‘Z‘) s[i] += (‘a‘ - ‘A‘);
                else if(s[i] == ‘.‘ || s[i] == ‘?‘ || s[i] == ‘!‘) flag = 1;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}
时间: 2024-10-14 00:10:57

URAL 1601. AntiCAPS (strings)的相关文章

URAL 1024 Permutations(LCM)

题意:已知,可得出 P(1) = 4, P(2) = 1, P(3) = 5,由此可得出 P(P(1)) = P(4) = 2. And P(P(3)) = P(5) = 3,因此.经过k次如上变换,最终可得,输入保证一定有解,求k. 分析: 1.能用数组表示映射就别用map,很耗时 2.序列中的每个数字经过这种变换都一定会变会自身,例如,一开始P(1) = 4,接下来P(P(1)) = P(4) = 2,再接下来P(P(P(1))) = P(P(4)) = P(2) = 1,只需三次,就可以变

LA 3026 Period (strings)

Period Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether

URAL 1137Bus Routes (dfs)

Z - Bus Routes Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1137 Description Several bus routes were in the city of Fishburg. None of the routes shared the same section of road, though commo

Ural 1119 Metro(DP)

题目地址:Ural 1119 因为还有一个可不可以穿的问题,所以需要再加一维.0代表可穿不可穿,可穿设置成0,不可穿就设置成无穷大.1代表当前这格的最短距离. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h

URAL 1290. Sabotage (sortings)

1290. Sabotage Time limit: 1.0 second Memory limit: 64 MB It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gone through many troubles. For example, he stayed alive a

HDU 1075 What Are You Talking About (strings)

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others) Total Submission(s): 15966    Accepted Submission(s): 5177 Problem Description Ignatius is so lucky that he met a Martian yesterday. But

URAL 1291 Gear-wheels(BFS)

Gear-wheels Time limit: 1.0 secondMemory limit: 64 MB - Arny! What happened with coordinator? Bad working coordinator was the everlasting trouble of their spaceship. Arny already had been working under this trouble while his not very attentive and re

URAL 1242 Werewolf(DFS)

Werewolf Time limit: 1.0 secondMemory limit: 64 MB Knife. Moonlit night. Rotten stump with a short black-handled knife in it. Those who know will understand. Disaster in the village. Werewolf. There are no so many residents in the village. Many of th

URAL 2047 Maths (数学)

对于一个数来说,它的除数是确定的,那么它的前驱也是确定的,而起点只能是1或2,所以只要类似筛法先预处理出每个数的除数个数 ,然后递推出每个数往前的延伸的链长,更新最大长度,记录对应数字.找到maxn以后,根据最后一个数找到前驱,并记录到ans数组中. 代码来自队友 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #