Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:发一下我的解法,先把字符串翻转过来,然后一路扫过去就可以了。

Posted by ludi at 2011-01-28 20:09:30 on Problem 1126
In Reply To:发一下我的解法,先把字符串翻转过来,然后一路扫过去就可以了。 Posted by:zhendeluzi at 2010-05-08 19:50:15
> 如题。
> 
> 反过来扫,然后记录当前的句子数,一旦小于1那肯定NO掉,如果最后全处理完了结果句子数还大于1,也NO掉,否则YES之。
> 
> #include <cstdio>
> #include <iostream>
> #include <iomanip>
> #include <algorithm>
> #include <cmath>
> #include <cstring>
> #include <string>
> #include <set>
> #include <vector>
> #include <iterator>
> 
> using namespace std;
> 
> bool
> solve_prob(string &sentence)
> {
> 	int nr_subsent(0);
> 
> 	reverse(sentence.begin(), sentence.end());
> 	for (string::iterator iter = sentence.begin(); iter != sentence.end(); ++iter) {
> 		if (*iter >= 'p' && *iter <= 'z') {
> 			++nr_subsent;
> 		} else if (*iter == 'N') {
> 			// nothing to be done.
> 		} else if (*iter == 'C' || *iter == 'D' || *iter == 'E' || *iter == 'I') {
> 			--nr_subsent;
> 		} else {
> 			return false; // 题上说是p-z,N,CDEI,实际上如果这儿写一句*(int *)0 = 0会RE。。。悲剧- -
> 		}
> 		if (nr_subsent < 1) {
> 			return false;
> 		}
> 	}
> 
> 	return (nr_subsent == 1);
> }
> 
> int main()
> {
> 	string sentence;
> 
> 	while (cin >> sentence) {
> 		cout << (solve_prob(sentence) ? "YES" : "NO") << endl;
> 	}
> 
> 	return 0;
> }
赞,从句子数这个角度解题非常高明!

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator