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

why i get CE ? compiled successfully in vs.net2005

Posted by forgotten at 2006-03-27 11:18:32 on Problem 2670
#include <fstream>
#include <vector>
#include <string>
#include <map>
using namespace std;

const string GOAL = "Sorcerer's Stone";
const int MaxLen = 100;

map<string, vector<string>> stone;
map<string, int> exist;
int ans;

void search(string key) {

	if (exist.find(key) == exist.end()) {
		ans ++;
		exist[key] = 1;
	}

 	if (stone[key].empty()) {
		return;
	}

	for (int i = 0; i < (int) stone[key].size(); i ++) {
		search(stone[key][i]);
	}
}

void getstones(char *names, vector<string> &stones) {

	int len = (int) strlen(names);
	string name;

	stones.clear();

	for (int i = 0; i < len; i ++) {
		if (names[i] == ',') {
			stones.push_back(name);
			name.clear();
			i ++;
			continue;
		}
		name.push_back(names[i]);
	}
	stones.push_back(name);
}

int main() {

	ifstream infile (stdin);
	ofstream outfile (stdout);

	int n, m;
	char names[MaxLen], buf[MaxLen], ch;
	vector<string> stones;
	
	while (infile >> n >> m, n && m) {

		infile.getline(buf, MaxLen);
		ans = 0;
		stone.clear();
		exist.clear();

		for (int i = 0; i < n; i ++) {
			infile.getline(names, MaxLen);
			exist[string(names)] = 1;
		}

		for (int i = 0; i < m; i ++) {
			infile.getline(names, MaxLen, ':');
			infile.get(ch);
			getstones(names, stones);
			infile.getline(names, MaxLen);
			stone[string(names)] = stones;
		}

 		search(GOAL);

		outfile << ans << "\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