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

【po shi shui】

Posted by KatrineYang at 2016-11-25 15:05:35 on Problem 1598
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

set<string> keywords;

struct excuse{
	string s;
	int cs;
}excuses[100];

bool cmp(const excuse& e1, const excuse& e2){
	return e1.cs > e2.cs;
}

bool isAlpha(char c){
	return (c>='a'&&c<='z') || (c>='A'&&c<='Z');
}

string toLower(string s){
	int len = s.length();
	string res = "";
	for(int i = 0; i < len; i++){
		if(s[i] >= 'A' && s[i] <= 'Z') {
			//cout << (char)(s[i] - ('A'-'a'));
			res += (s[i] - ('A'-'a'));
		}
		else res += s[i];
	}
	return res;
}

int parse(string s){
	int state = 0;
	string col;
	int len = s.length();
	int gs = 0;
	for(int i = 0; i < len; i++){
		if(state==0 && isAlpha(s[i])){
			col += s[i];
			state = 1;
		}
		else if(state==0){
			continue;
		}
		else if(isAlpha(s[i])){
			col += s[i];
		}
		else{
			if(keywords.find(toLower(col)) != keywords.end()) gs++;
			///cout << "col: " << col << "tolower: " << toLower(col) << endl;
			col = "";
			state = 0;
		}
	}
	if(state && keywords.find(toLower(col)) != keywords.end()) gs++;
	return gs;
}

int main() {
	int cnt = 0;
	int n,m;
	while(cin >> n >> m){
		cnt++;
		cout << "Excuse Set #" << cnt << endl;
		keywords.clear();
		for(int i = 0; i < n; i++){
			string s;
			cin >> s;
			keywords.insert(s);
		}
		for(int i = 0; i < m; i++){
			string s;
			while(!s.length()) getline(cin, s);
			excuses[i].s = s;
			int cs = parse(s);
			excuses[i].cs = cs;
			//cout << s << " " << cs << endl;
		}
		sort(excuses, excuses+m, cmp);
		int gs = excuses[0].cs;
		//cout << "geshu:" << gs << endl;
		for(int i = 0; i < m; i++){
			if(excuses[i].cs != gs) break;
			cout << excuses[i].s << endl;
		}
		cout << 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