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

小弟第一次做题,没想到入门如此难,总是wrong answer。使用了一些STL

Posted by deliver at 2004-10-10 20:21:44 on Problem 1002
使用了一些STL,少写了一些代码,不知道这样做好不好。
#include<iostream>
#include<string>
#include<set>
#include<iterator>
#include<iomanip>
using namespace std;
int turn[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
long convert(string &s) //转换成数字
{
	long total=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]>='0'&&s[i]<='9')
			total=total*10+(s[i]-'0');
		else if(isupper(s[i]))
			total=total*10+turn[s[i]-'A'];
	}
	return total;
}
void output(long num)//将数字按照格式输出
{
	int up=num/10000;
	int down=num-up*10000;
	cout<<setfill('0')<<setw(3)<<up<<"-"<<setfill('0')<<down;
}
	
int main()
{
	int times;
	cin>>times;
	multiset<long> ml;
	for(int k=0;k<times;k++)
	{
		string s;
		cin>>s;
		ml.insert(convert(s));
	}
	bool flag=true;
	for(multiset<long>::iterator i=ml.begin();i!=ml.end();)//判断重复与否并输出
	{
		int count=ml.count(*i);
		if(count!=1)
		{
			flag=false;
			output(*i);
			cout<<" "<<count<<endl;
		}
		advance(i,count);
	}
	if(flag)
	{
		cout<<"No duplicates."<<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