⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1002.txt

📁 北大ACM题目例程 详细的解答过程 程序实现 算法分析
💻 TXT
字号:


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define debug 0
#define POINTS 10
#define INF 30000

#if debug
    #define NMAX 100
#else
    #define NMAX 100003
#endif
int cmp(const void *a,const void *b)    
{
	return *(int*)a-*(int*)b;
}

change(char *str,int &no)
{
	int i,j=0;
	char sno[10]={0};
	char tmp;
	for(i=0;i<strlen(str);i++)
	{
		tmp=str[i];
		if(tmp=='-')
			continue;
		if(tmp>'9')
		{
			if(tmp<'Q')
				tmp=(tmp-'A')/3+2+'0';
			else
				tmp=(tmp-1-'A')/3+2+'0';
		}
		sno[j++]=tmp;
	}
	sno[j]=0;
	no=atoi(sno);
}
int a[NMAX];
int main()
{

#if debug 	
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int N,i;
	int no;
	char str[50],tmp[50];
	
	
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%s",str);
		
		change(str,no);
		a[i]=no;
	}
	qsort(a,N,sizeof(int),cmp);
	int cp=a[0],sum=1;
	int flag=0;

	for(i=1;i<N;i++)
	{
		if(a[i]==a[i-1])
			sum++;
		else
		{
			
			if(sum>1)
			{
				flag=1;
				ltoa(a[i-1],tmp,10);
				int len=strlen(tmp);
				for(int j=0;j<8;j++)
				{
					str[j]='0';
				}
				strcpy(str+7-len,tmp);
				str[7]=0;	
				for(j=0;j<7;j++)
				{
					if(j==2)
						printf("%c-",str[j]);
					else
						printf("%c",str[j]);
				}
				printf(" %d\n",sum);
				

			}
			sum=1;
		}
	}
	if(sum>1)
	{
		flag=1;
		ltoa(a[i-1],tmp,10);
		int len=strlen(tmp);
		for(int j=0;j<8;j++)
		{
			str[j]='0';
		}
		strcpy(str+7-len,tmp);
		str[7]=0;	
		for(j=0;j<7;j++)
		{
			if(j==2)
				printf("%c-",str[j]);
			else
				printf("%c",str[j]);
		}
		printf(" %d\n",sum);
		

	}

	if(flag==0)
		printf("No duplicates.");

#if debug
	fclose(stdin);
	fclose(stdout);
#endif
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -