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

我想复杂了么???还WA掉了。。。

Posted by 771385494 at 2012-10-01 16:07:09 on Problem 3096
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main()
{
	string str;
	int i,j = 0;
	set<string> s;
	set<string>::iterator iter;
	while(cin >> str && str.compare("*") != 0) {
		int D = 0,length = str.length();
		int maxD = length - 2;//最长子串长度
		string sub = "";
		while(D <= maxD) {
			for(i = 0;i < length - 1 - D;i++) {//子串个数
				for(j = i;j <= length - 1;j += D + 1) {//
					sub += str.at(j);
					if(sub.length() == 2)
						break;
				}
				if(s.find(sub) != s.end())
					break;
				else
					s.insert(sub);
				sub = "";
			}
			if(i != length - 1 - D) {
				cout << str << " is NOT surprising.\n";
				break;
			}
			D++;
			s.clear();
		}
		if(D == maxD + 1)
			cout << str << " is surprising.\n";
	}
	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