PAT b1011-b1015题解

120 篇文章 0 订阅
109 篇文章 0 订阅

一、b1011

#include <cstdio>

int main(){
	int T, tcase = 1;
	scanf("%d", &T);
	while(T--){
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		if(a + b > c){
			printf("Case #%d: true\n", tcase++);
		}
		else{
			printf("Case #%d: false\n", tcase++);
		}
	}
	return 0;
} 

二、b1012

#include <cstdio>
int main(){
	int count[5] = {0};
	int ans[5] = {0};
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int tmp;
		scanf("%d", &tmp);
		if(tmp % 5 == 0){
			if(tmp % 2 == 0){
				ans[0] += tmp;
				count[0]++;
			}
		}
		if(tmp % 5 == 1){
			count[1]++;
			if(count[1] % 2 == 0){
				tmp = -tmp;
			}
			ans[1] += tmp;
		}
		if(tmp % 5 == 2){
			count[2] ++;
			ans[2] = count[2];
		}
		if(tmp % 5 == 3){
			count[3]++;
			ans[3] += tmp;
		}
		if(tmp % 5 == 4){
			count[4]++;
			if(tmp > ans[4]){
				ans[4] = tmp;
			}
		}
	}
	if(count[0] == 0)
	printf("N ");
	else
	printf("%d ", ans[0]);
	if(count[1] == 0)
	printf("N ");
	else
	printf("%d ", ans[1]);
	if(count[2] == 0)
	printf("N ");
	else
	printf("%d ", ans[2]);
	if(count[3] == 0)
	printf("N ");
	else
	printf("%.1f ", (double)ans[3] / count[3]);
	if(count[4] == 0)
	printf("N");
	else
	printf("%d", ans[4]);
	return 0;
}

三、b1013

#include <cstdio>

const int maxn = 1000001;
int prime[maxn], num = 0;
bool p[maxn] = {0};
void Find_Prime(int n){
	for(int i = 2; i < maxn; i++){
		if(p[i] == false){
			prime[num++] = i;
			if(num >= n) break;
			for(int j = i + i; j < maxn; j += i){
				p[j] = true;
			}
		}
	}
}

int main(){
	int m, n, count = 0;
	scanf("%d%d", &m, &n);
	Find_Prime(n);
	for(int i  = m; i <= n; i++){
		printf("%d", prime[i - 1]);
		count++;
		if(count % 10 != 0 && i < n) printf(" ");
		else printf("\n");
	}
	return 0;
}

四、b1014

#include <cstdio>
#include <cstring>

int main(){
	char week[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
	char str1[65], str2[65], str3[65], str4[65];
	gets(str1);
	gets(str2);
	gets(str3);
	gets(str4);
	int len1 = strlen(str1);
	int len2 = strlen(str2);
	int len3 = strlen(str3);
	int len4 = strlen(str4);
	int i;
	for(i = 0; i < len1 && len2; i++){
		if(str1[i] == str2[i] && str1[i] >= 'A' && str1[i] <= 'G'){
			printf("%s ", week[str1[i] - 'A']);
			break;
		}
	}
	for(i++; i < len1 && i < len2; i++){
		if(str1[i] == str2[i]){
			if(str1[i] >= '0' && str1[i] <= '9'){
				printf("%02d:", str1[i] - '0');
				break;
			}
			else if(str1[i] >= 'A' && str1[i] <= 'N'){
				printf("%02d:", str1[i] - 'A' + 10);
				break;
			}
		}
	}
	for(i = 0; i < len3 && i < len4; i++){
		if(str3[i] == str4[i]){
			if((str3[i] >= 'A' && str3[i] <= 'Z') || (str3[i] >= 'a' && str3[i] <= 'z')){
				printf("%02d", i);
				break;
			}
		}
	}
	return 0;
} 

五、b1015

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Student{
	char id[10];
	int de, cai, sum;
	int flag;
}stu[100010];

bool cmp(Student a, Student b){
	if(a.flag != b.flag){
		return a.flag < b.flag;
	}
	else if(a.sum != b.sum){
		return a.sum > b.sum;
	}
	else if(a.de != b.de){
		return a.de > b.de;
	}
	else{
		return strcmp(a.id, b.id) < 0;
	}
}

int main(){
	int n, L, H;
	scanf("%d%d%d", &n, &L, &H);
	int m = n;
	for(int i = 0; i < n; i++){
		scanf("%s%d%d", stu[i].id, &stu[i].de, &stu[i].cai);
		stu[i].sum = stu[i].de + stu[i].cai;
		if(stu[i].de < L || stu[i].cai < L){
			stu[i].flag = 5;
			m--;
		}
		else if(stu[i].de >= H && stu[i].cai >= H){
			stu[i].flag = 1;
		} 
		else if(stu[i].de >= H && stu[i].cai < H){
			stu[i].flag = 2;
		}
		else if(stu[i].de >= stu[i].cai){
			stu[i].flag = 3;
		}
		else{
			stu[i].flag = 4;
		}
	} 
	sort(stu, stu + n, cmp);
	printf("%d\n", m);
	for(int i = 0; i < m; i++){
		printf("%s %d %d\n", stu[i].id, stu[i].de, stu[i].cai);
	}
	return 0;
}






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值