PAT 甲级 1039 PAT Ranking 个人错误总结

这题有点卡,思路一开始就是对的,就是卡了最后一个点。
因为我用的getchar读数,竟然导致了爆栈,问题是我不知道这样算有问题,我至今还不太能理解为什么,明明每次调用函数就只用了4次getchar。。用完就return了,理论上栈顶多就占那4个空。
ac代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;
int hashc(char a[]){
	int n=0;
	for(int i=0;i<3;i++){
		n=n*26+(a[i]-'A');
	}
	n=n*10+(a[3]-'0');
	return n;
} 
void printn(int n){
	char a[5]={};
	a[0]=n%10+'0';
//	putchar(a[0]);
	n/=10;
	for(int i=0;i<3;i++){
		a[i+1]=n%26+'A';
		n/=26;
	}
	reverse(a,a+4);
	printf("%s",a);
}

vector<int > stu[180000];
int main(){
	int n,k,c,m;
	char str[5];
	int step;
	scanf("%d %d",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d %d",&c,&m);
		for(int j=0;j<m;j++){
			scanf("%s",&str);
			step=hashc(str);
			stu[step].push_back(c);	
		}
	}
	int size;
	for(int i=0;i<n;i++){
		scanf("%s",&str);
		step=hashc(str);
		size=stu[step].size();
		sort(stu[step].begin(),stu[step].end());
		printn(step);
		printf(" %d",size);
		for(int j=0;j<size;j++){
			printf(" %d",stu[step][j]);
		}
		printf("\n");
	}
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值