Timus 1601. AntiCAPS 修正大写句子

The blonde Angela has a new whim: internet chats. Of course, as any blonde, she writes her messages using the upper case. You are the moderator of Angela‘s favorite chat and you‘re fed up with her upper-case
messages. The problem is that Angela does not respond to your warnings. You decided to write a simple antiCAPS 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 other letters 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, exclamation and 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?

就是修正个全是大写的句子。

这里注意一点(as in codes‘ comment):

keep the state, because blonde would do anything, and put the comma, in one line, and start typing another line.

#include <string>
#include <iostream>
using namespace std;

void toLowerCase(string &s, bool &senBegin)
{
	for (unsigned i = 0; i < s.size(); i++)
	{
		if (‘ ‘ == s[i]) continue;
		if (senBegin)
		{
			if (‘A‘ <= s[i] && s[i] <= ‘Z‘ || ‘a‘ <= s[i] && s[i] <= ‘z‘)
			{
				s[i] = toupper(s[i]);
				senBegin = false;
			}
			continue;
		}
		if (‘.‘ == s[i] || ‘?‘ == s[i] || ‘!‘ == s[i]) senBegin = true;
		s[i] = tolower(s[i]);
	}
}

int AntiCAPS1601()
{
	string s;
	bool senBegin = true;//keep the state, because blonde would do anything, and put the comma, in one line, and start typing another line.
	while (getline(cin, s))
	{
		toLowerCase(s, senBegin);
		cout<<s<<endl;
	}
	return 0;
}
时间: 2024-10-29 18:06:07

Timus 1601. AntiCAPS 修正大写句子的相关文章

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 h

将一个句子中单词的首字母转换为大写

如:      hello my name is zeroinger , nice to meet you! 转换后:      Hello My Name Is Zeroinger , Nice To Meet You! 代码:      #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include

给定一个英文句子(一个只有字母的字符串),将句中所有单词变为有且只有首字母大写

def cap_string(sentence): sentence=' '.join([i.title() for i in sentence.split()]) return sentence s='''Python is a programming language that lets you work quickly and integrate systems more effectively''' print cap_string(s) 输出: Python Is A Programm

编写一个正则表达式:检查一个句子是否以大写字母开头,以句号结尾.

package 正则表达式; import java.util.regex.Pattern; public class Test2 { public static void main(String[] args) { String len="^[A-Z].*[\\.]$"; String s1="A line terminator."; String s2="Wangdan1600"; String s3="asdfgh.";

1165: 零起点学算法72——首字母变大写

1165: 零起点学算法72--首字母变大写 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 705  Accepted: 439[Submit][Status][Web Board] Description 输入一个英文句子,将每个单词的第一个字母改成大写字母. Input 输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行. Output 请输出按照要求改写后的英文句

[2016-02-24][UVA][1601][The Morning after Halloween]

时间:2016-02-24 15:49:41 星期三 题目编号:UVA 1601 题目大意:给定一个迷宫图,至多3个小写字母和等数目大写字符,求小写字母移动到大写字母的最少步数 迷宫宽度范围是4~16,字母个数是1~3, 分析:求最少步数,BFS,知道终点状态,可以用双向bfs优化 方法:BFS //单向bfs #include<iostream> #include<cstdio> #include<queue> #include<cstring> #inc

hdu 2026 首字母变大写(java)

问题: 将小写换成大写,之前用a=(char)(a+32)的形式,并没有效果,原因不明. 有函数:a[0]=Character.toUpperCase(a[0]);可以用. 首字母变大写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37323    Accepted Submission(s): 20817 Problem Desc

税号输入框 将input框中的输入自动转化成半角大写

这两天出了这么一个需求,输入税号的时候,需要自动将其转化为半角大写,并且阻止标点符号中文汉字的输入.(下面会有:全半角转换.文本框选中.光标位置判断.设置光标位置 这些内容) 然后我就开始了慢慢查找资料之路. 首先查了全半角的区别以及如何转化. var str = "中文;:a"; for (var i = 0; i < str.length; i++) { if (str[i].match(/[\u0000-\u00ff]/)) { console.log("半角字符

HDOJ 2026首字母变大写

首字母变大写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30463    Accepted Submission(s): 17060 Problem Description 输入一个英文句子,将每个单词的第一个字母改成大写字母. Input 输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行. Outp