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,要么OLE,恳请哪位高手看看,或者给点测试数据,都快疯了

Posted by Ontheline at 2008-07-24 18:59:15 on Problem 1016
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <iomanip>
using namespace std;
class Inventory
{
public:
	Inventory(string t):number(t)
	{

	}
	~Inventory()
	{
		
	}
	string Inventorying();
private:
	string number;
	map<char,int> iteratmap;
	
};

string Inventory::Inventorying()
{
	char ch;
	string resultstr;
	string strt;
	int n=number.size();
	int i=0;
	for (i=0;i<n;i++)
	{
		iteratmap[number[i]]++;
	}
	int j=0;
	int value;
	map<char,int>::iterator it=iteratmap.begin();
	vector<char> chtemp;
	while (it!=iteratmap.end())
	{
		chtemp.push_back((*it).first);
		it++;
	}
	n=chtemp.size();
	for (i=1;i<n;i++)
	{
		ch=chtemp[i];
		j=i-1;
		while (j>=0 && ch < chtemp[j])
		{
			chtemp[j+1]=chtemp[j];
			j--;
		}
		chtemp[j+1]=ch;
		
	}
	for (i=0;i<n;i++)
	{
		
		value=iteratmap[chtemp[i]];
		if (value>10)
		{
			int k1=value/10;
			int k2=value-k1*10;
			ch=k1+'0';
			resultstr.insert(resultstr.end(),ch);
			ch=k2+'0';
			resultstr.insert(resultstr.end(),ch);
		}
		else
		{
			ch=value+'0';
			resultstr.insert(resultstr.end(),ch);
		}
		ch=chtemp[i];
		resultstr.insert(resultstr.end(),ch);
	}
	iteratmap.clear();
	number=resultstr;
	return resultstr;
}
int isloop(vector<string> st_15);

int main()
{
	string t;
	string pt;
	string originalstr;
	vector<string> store15;
	bool flag=false;
	int i=0;
	while (cin >> t)
	{
		if (t=="-1")
		{
			break;
		}
		Inventory a(t);
		originalstr=t;
		store15.push_back(t);
		while (i<15)
		{
			pt=t;
			t=a.Inventorying();
			store15.push_back(t);
			if (i==0 && pt==t)
			{
				cout << pt << " is self-inventorying" <<endl;
				break;
			}
			else if(pt==t && i>0)
			{
				
				cout << originalstr << " is self-inventorying after " << i << " steps" <<endl;
				break;
			}
			else
			{
				for (int j=store15.size()-2;j>=0;j--)
				{
					if (store15[j]==t)
					{
						cout << originalstr << " enters an inventory loop of length " << i-j+1 << endl;
						flag=true;
						break;
					}
				}
				if (flag)
				{
					flag=false;
					break;
				}
			}
			i++;
		}
		if (i>=15)
		{
			cout << originalstr << " can not be classified after 15 iterations" << endl; 
		}
		store15.clear();
		i=0;
	}
	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