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

郁闷,谁能帮小弟看一下程序(c++).....不胜感激

Posted by wangcheng711 at 2003-11-26 21:39:20 on Problem 1002
#include <iostream.h>

void swap(int &a, int &b)
{
	int temp;
	temp =a;
	a = b;
	b = temp;
}

int part(int *a, int low, int high)
{
	int pivpos=low;
	int pivot = a[low];
	for (int i=low+1; i<=high; i++)
	{
		if (a[i]<pivot && ++pivpos != i)
			swap(a[pivpos], a[i]);
	}
		swap(a[low], a[pivpos]);
		return pivpos;
}


void sort(int *a, int left, int right)
{
	if (left < right)
	{
		int pivpos = part(a, left, right);
		sort(a, left, pivpos-1);
		sort(a, pivpos+1, right);
	}
}



void main()
{
	int num;
	int *a;
    cin>>num;
	a = new int[num];
	
	int j=0;     //the totle numbers of string and digital
	int j1=0;   //the position of string
	char p[40];	

	for (int i=0; i<num; i++)
	{
		a[i] = 0;
		j = 0;
		j1 =0;
		cin>>p;
		while (1)
		{
			if (p[j1]>=48&&p[j1]<=57) { a[i] = (p[j1]-48) + a[i]*10; j++; if (j==7) break;}

			if (p[j1]>=65&&p[j1]<=80) { a[i] = (2+(p[j1]-65)/3) + a[i]*10; j++;if (j==7) break;}

			if (p[j1]>=82&&p[j1]<=89) { a[i] = (2+(p[j1]-66)/3) + a[i]*10; j++;if (j==7) break;}

			if (p[j1]>=97&&p[j1]<=112) { a[i] = (2+(p[j1]-97)/3) + a[i]*10; j++;if (j==7) break;}
			
			if (p[j1]>=114&&p[j1]<=121) { a[i] = (2+(p[j1]-98)/3) + a[i]*10; j++;if (j==7) break;}
			j1++;				
		}
			
	}
	sort(a, 0, num-1);  //快速排序
	for (i=0; i<num; i++)
	{
		cout<<a[i]<<endl;
	}
	int count=1;
	int sig = 0;
	i = 0;
	while (i<num)
	{
		for (int j=i+1; a[i]==a[j]; j++)
		{
			count++;
		}
		if (count>1) {cout<<a[i]/10000<<"-"<<a[i]-a[i]/10000*10000<<" "<<count<<endl; sig = 1; count=1;}
		i = j-1;
		i++;		
	}
	if (sig == 0) 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