zl程序教程

您现在的位置是:首页 >  后端

当前栏目

散列表在PAT中的应用,例题:1041,1050,1084

列表应用 PAT 例题
2023-09-14 09:13:20 时间

1.PAT 1041

题目链接:https://www.patest.cn/contests/pat-a-practise/1041

(1).题意分析

a:找出第一个出现的且不重复的数字

(2).AC代码

#include <stdio.h>

/*
1.题意分析:第一个出现的唯一的号码则是胜者 
*/
#define N 100010

int array[N];//用来存储选择的数据
int main(){
	int number, hashArray[10002];//输入打赌的人 , 散列表 
	scanf("%d",&number);	
	int i;
	int max = 0;//表示输入中的最大值 
	for(i = 0;i<number;i++){
		scanf("%d",&array[i]);
		if(array[i] > max){
			max = array[i];//赋值 
		} 
		hashArray[array[i]]++; //将其增加 
	} 

	for( i = 0;i< number ;i++){
		if(hashArray[array[i]]!=0 && hashArray[array[i]]==1){
			printf("%d",array[i]);
			break;
		}
	}
	if(i == number){
		printf("None\n");
	}
} 

/**
7 5 31 5 88 67 88 17
5 888 666 666 888 888
*/

2.PAT 1050

(0)题目:https://www.patest.cn/contests/pat-a-practise/1050

(1)题意分析

a.从字符串s1中删除字符串s中出现的字符。

(2)AC代码

#include <stdio.h>
#include <string.h>
 
#define N 10002

char str1[N] ,str2[N];
int ascii[128];//表示128个ASCII码表 

int main(){
	gets(str1);
	gets(str2);//输入两个字符串
	int len1 = strlen(str1),len2 = strlen(str2);//求出两个字符串的长度
	
	int i = 0 ;
	for(i = 0;i < len2; i++	){
		ascii[str2[i]]++; 
		
	}
	
	for(i = 0;i<len1;i++){
		if(ascii[str1[i]]>0){
			continue;
		}
		else{
			printf("%c",str1[i]);
		}
	} 	
}
/**
Theay are students.
aeiou 
*/