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

Re:printf和scanf如何用?哪位牛人帮我改下程序,把CIN,COUT都换掉 谢谢拉!

Posted by youngtrips at 2007-10-05 11:29:33 on Problem 1002
In Reply To:printf和scanf如何用?哪位牛人帮我改下程序,把CIN,COUT都换掉 谢谢拉! Posted by:superand at 2007-10-05 11:01:20
#include<iostream>
//#include<fstream>
using namespace std;
const int hashmax=200000;
int ha[hashmax],bj[hashmax],a[100001];
int n,p,num,cont,i,x;
char  ch;

void sort(int ar[], int x,int y)
{
 if (x<y)
 {
 int i=x,j=y,k=x,t;
 while (i!=j)
    {
        while (ar[i]<ar[k]) i++; t=ar[i];ar[i]=ar[k];ar[k]=t;
        while (ar[k]<ar[j]) j--; t=ar[j];ar[j]=ar[k];ar[k]=t;
 }
 sort(ar,x,k-1);
 sort(ar,k+1,y);
 }
}

int hash(int key)
{
	int x;
	x=key/99;
	while (ha[x]!=0 && ha[x]!=key) x++;
	return x;
}
int main()
{
   // ifstream cin("input.txt");
	//cin>>n;
	scanf("%d",&n);
	memset(bj,0,sizeof(bj));
	memset(ha,0,sizeof(ha));
	cont=0;
	for (i=1; i<=n; i++){
		p=0; num=0;
		while (p!=7) {
			//cin>>ch;
			scanf("%c",&ch);
			if (ch!='-') {
				p++; num=num*10;
				if   (ch=='0') {num=num+0;}else 
				if   (ch=='1') {num=num+1;}else 
				if 	 (ch=='A'||ch=='B'||ch=='C'||ch=='2') {num=num+2;} else
				if 	 (ch=='D'||ch=='E'||ch=='F'||ch=='3') {num=num+3;} else
				if 	 (ch=='G'||ch=='H'||ch=='I'||ch=='4') {num=num+4;} else
				if 	 (ch=='J'||ch=='K'||ch=='L'||ch=='5') {num=num+5;} else
				if 	 (ch=='M'||ch=='N'||ch=='O'||ch=='6') {num=num+6;} else
				if 	 (ch=='P'||ch=='R'||ch=='S'||ch=='7') {num=num+7;} else
				if 	 (ch=='T'||ch=='U'||ch=='V'||ch=='8') {num=num+8;} else
				if 	 (ch=='W'||ch=='X'||ch=='Y'||ch=='9') {num=num+9;};
			}
		}
		x=hash(num);
		if (bj[x]==0) {cont++;a[cont]=num;ha[x]=num; }
		bj[x]++;
	}
	sort(a,1,cont);
	int nocf=0,t,y,j;
	for (i=1;i<=cont;i++)
		if (bj[hash(a[i])]>1) 
	{
		nocf=1;
		x=a[i]; y=1000000;
		for (j=1;j<=7;j++){
			t=x/y;
			//cout<<t;
			printf("%d",t);
			if (j==3)
				printf("-");
				//cout<<"-";
			x=x%y;
			y=y/10;
		}
		//cout<<" "<<bj[hash(a[i])]<<endl;
		printf(" %d\n",bj[hash(a[i])]);
	}
	if (nocf==0)
		printf("No duplicates.\n");
		//cout<<"No duplicates."	;
		
//	cin.close();
	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