首页 > ACM题库 > HDU-杭电 > HDU 3129-The Brave Sir Robin’s cAsE cOrReCtOr[解题报告]HOJ
2014
03-03

HDU 3129-The Brave Sir Robin’s cAsE cOrReCtOr[解题报告]HOJ

The Brave Sir Robin’s cAsE cOrReCtOr

问题描述 :


What is the air speed velocity…

Dissatisfied with the loud and constant pronouncements of his alleged misdeeds by a trio of indefatigable minstrels, the brave knight Sir Robin wishes to exercise his authority by modifying their lyrics. The minstrels were happy to provide printed transcripts of their songs, and cheerfully announced that they would not change a word of them.

Undaunted, the brave (and crafty) Sir Robin scrutinized the documents and noticed that their loudest inflections were indicated by capital letters and realized that he could at least lower their voices. This, he reasoned, could be accomplished by replacing upper case letters with lower case letters ("Case correction", from his perspective). These modifications could be forced upon the singers by insistence upon proper usage of the King’s English. Not all letters can be lower case, however, as the King’s English mandates some letters must be upper case.

Strangely hesitant about performing "case correction" personally, the brave, crafty (and managerially capable) Sir Robin humbly requests you write a program to perform a first pass of case correction for the songs. There will still be some corrections required after this program is used.

As your program reads the file, it must force to upper case all alphabetic characters that follow terminal punctuation marks (period, question mark, and exclamation point) with only white space or parentheses characters following. All other alphabetic characters are to be forced to lower case. Note that decimal numbers are not to be followed by an upper case character unless the number itself is followed by a terminal punctuation mark.

输入:

The input file contains the text that you are converting. Your conversions should be based on the rules given by Brave Sir Robin above.

输出:

The input file contains the text that you are converting. Your conversions should be based on the rules given by Brave Sir Robin above.

样例输入:

The Brave Sir Robin took a short walk in a dark forest where rabbits did stalk. a
ray of sunlight made him jump from his own shadow with A FACE AS PALE AS CHALK.

样例输出:

the brave sir robin took a short walk in a dark forest where rabbits did stalk. A
ray of sunlight made him jump from his own shadow with a face as pale as chalk.

#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cctype>
#include <list>
#include <hash_map>
#include <stack>
#include <hash_set>
#include <hash_map>
#include <sstream>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <hash_map>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
const int inf=1e9+7;
const long long linf=1e18;
typedef long double lf;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long double,long double> pdd;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
int main(){
	bool first=true;
	string s;
	while (getline(cin,s)){
		for (int i=0;i<s.size();i++)
		{
			if (i==0&&!first){
				while (i<s.size()&&(s[i]=='('||s[i]==')'))
					i++;
				s[i]=toupper(s[i]);
			}
			else if (s[i]=='.'||s[i]=='?'||s[i]=='!'){
				do{
					i++;
				}while (i<s.size()&&(s[i]==' '||s[i]=='('||s[i]==')'));
				if (i==s.size()) break;
				s[i]=toupper(s[i]);
			}
			else s[i]=tolower(s[i]);
		}
		first=false;
		cout<<s<<endl;
	}
	return 0;
}

  1. 有一点问题。。后面动态规划的程序中
    int dp[n+1][W+1];
    会报错 提示表达式必须含有常量值。该怎么修改呢。。

  2. 您没有考虑 树的根节点是负数的情况, 若树的根节点是个很大的负数,那么就要考虑过不过另外一边子树了

  3. a是根先忽略掉,递归子树。剩下前缀bejkcfghid和后缀jkebfghicd,分拆的原则的是每个子树前缀和后缀的节点个数是一样的,根节点出现在前缀的第一个,后缀的最后一个。根节点b出现后缀的第四个位置,则第一部分为四个节点,前缀bejk,后缀jkeb,剩下的c出现在后缀的倒数第2个,就划分为cfghi和 fghic,第3部分就为c、c

  4. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。