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 wrong answer?

Posted by madongtest at 2006-07-25 11:40:36 on Problem 2896
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<cstdlib>
using namespace std;

struct Change{
	int year;
	int model;
	string name;
	int ith;
	string bechg;
}change[10000];
int find(string &str)
{
	for(int i = 0; ; i++)
		if(change[i].name == str)
			return i;
}
int find3(int begin,int small,int len)
{
	for(int i = begin; i < len; i++)
		if(change[i].model == 3 && change[i].year <= small)
			return i;
		return -1;
}
bool cmp(const Change &a,const Change &b)
{
	return  a.name < b.name || (a.name == b.name && a.year < b.year);
}
int adjust(string &str,int i,string &head)
{
	if(change[i].model == 1){
		char c[2] = {str[change[i].ith-1],'\0'};
		string t(c);
		str.insert(change[i].ith-1,t);
	}
	else if(change[i].model == 2){
		char t = str[change[i].ith-1];
		str[change[i].ith-1] = str[change[i].ith];
		str[change[i].ith] = t;
	}
	else
		head = change[i].bechg;
	return 0;
}
int main()
{
	int num,i;
	cin >> num;
	string anum, aname;
	map<string,string> mp;
	map<string,string> fmp;
	for(i = 0; i < num; i++){
		cin >> anum >> aname;
		mp[anum] = aname;
		fmp[aname] = anum;
	}
    cin >> num;
	for(i = 0; i < num; i++){
		cin >>change[i].year >> change[i].model >>change[i].name;
		if(change[i].model == 3)
			cin >> change[i].bechg;
		else
			cin >> change[i].ith;
	}
	sort(change,change+num,cmp);
	int begin,end;
	string phnum;
    while(cin >> begin >> end >> phnum){
		if(begin == 0 && end == 0)
			return 0;
		string head;
		int dex,chu = 0;
		while((dex = find3(chu,begin,num)) != -1){
			chu = dex+1;
			mp[fmp[change[dex].name]] = "";
			mp[change[dex].bechg] = change[dex].name;
		}
		for(i = 0; i < 5; i++){
            head = phnum.substr(0,i+1);
			if(mp[head] != "")
				break;
        }
		phnum.erase(0,i+1);
		int index = find(mp[head]);
		string flag = head;
		while(change[index].name == mp[flag]){
			if(change[index].year <= begin || change[index].year > end){
				index++;
				continue;
			}
			adjust(phnum,index,head);
			index++;
		}
		cout << head << phnum << endl;
	}
}

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