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

用 East Central North America 1999 的16个输入文件测试,对照答案,觉得没错,为何 Wrong answer?

Posted by pplower at 2014-10-03 10:51:18 on Problem 1002 and last updated at 2014-10-03 12:23:42
用C++提交的
请指教,多谢了
代码如下:
加入对QZ的判断也是WA

好吧,我找到原因了,char temp;改成全局变量就可以了。
PS:我在本地用的是 VS2010 不开优化。

#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int N=0,i,j;
string line;
vector<string> list,res; 
vector<string>::iterator item;
int cont;

int main()
{
	cin>>N;
	getchar();
	while(N>0)  
	{  
		getline(cin,line); 
		if(line.length()!=0)
		{
			list.push_back(line);  
			N--;
		}
	}
	line = "";
	for(i=0,item=list.begin();item!=list.end();item++)
	{
		char temp;
		for(int j=0;j<(*item).length();j++)
		{
			temp=(*item)[j];
			if(temp!='-')
			{
				if(temp=='A'||temp=='B'||temp=='C')
					temp = '2';
				else if(temp=='D'||temp=='E'||temp=='F')
					temp = '3';
				else if(temp=='G'||temp=='H'||temp=='I')
					temp = '4';
				else if(temp=='J'||temp=='K'||temp=='L')
					temp = '5';
				else if(temp=='M'||temp=='N'||temp=='O')
					temp = '6';
				else if(temp=='P'||temp=='R'||temp=='S')
					temp = '7';
				else if(temp=='T'||temp=='U'||temp=='V')
					temp = '8';
				else if(temp=='W'||temp=='X'||temp=='Y')
					temp = '9';
				line.append(&temp);
			}
		}
		res.push_back(line);
		line = "";
	}
	sort(res.begin(), res.end());
	bool flag=true;
	for(item=res.begin(),cont=1;item!=res.end();item++,cont=1)
	{
		while((item+1)!=res.end()&&(*item)==(*(item+1)))
		{
			cont++;
			item++;
		}
		if(cont>1)
		{
			(*item).insert((*item).begin()+3,'-');
			cout<<(*item)<<" "<<cont<<endl;
			flag = false;
		}
	}
	if(flag == true)
		cout<<"No duplicates."<<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