PAT b1036-b1040题解

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

1、b1036

#include <cstdio>

int main(){
	int col, row;
	char symbol;
	scanf("%d %c", &col, &symbol);
	if(col % 2 == 0){
		row = col / 2;
	}
	if(col % 2 == 1){
		row = col / 2 + 1;
	}
	for(int i = 0; i < col; i++){
		printf("%c", symbol);
	}
	printf("\n");
	for(int i = 0; i < row - 2; i++){
		printf("%c", symbol);
		for(int i = 0; i < col -2; i++){
			printf(" ");
		}
		printf("%c", symbol);
		printf("\n");
	} 
	for(int i = 0; i < col; i++){
		printf("%c", symbol);
	}
	return 0;
}

2、b1037

#include <cstdio>

const int Gallon = 17 * 29;
const int Sickle = 29;
int main(){
	int a1, b1, c1;
	int a2, b2, c2;
	scanf("%d.%d.%d %d.%d.%d", &a1, &b1, &c1, &a2, &b2, &c2);
	int price = a1 * Gallon + b1 * Sickle + c1;
	int money = a2 * Gallon + b2 * Sickle + c2;
	int change = money - price;
	if(change < 0){
		printf("-");
		change = -change; 
	}
	printf("%d.%d.%d\n", change / Gallon, change % Gallon / Sickle, change % Sickle);
	return 0;
}

3、b1038

#include <cstdio>

int grade[101] = {0};

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int score;
		scanf("%d", &score);
		grade[score]++;
	}
	int m;
	scanf("%d", &m);
	for(int i = 0; i < m; i++){
		int score;
		scanf("%d", &score);
		if(i == m -1){
			printf("%d", grade[score]);
		}
		else{
			printf("%d ", grade[score]);
		}
	}
	return 0;
}

4、b1039

#include <cstdio>
#include <cstring>

int hashTable[128] = {0};
char str1[1010];
char str2[1010];
int count = 0;

int main(){
	gets(str1);
	int len1 = strlen(str1);
	for(int i = 0; i < len1; i++){
		hashTable[str1[i]]++;
	}
	gets(str2);
	int len2 = strlen(str2);
	for(int i = 0; i < len2; i++){
		hashTable[str2[i]]--;
		if(hashTable[str2[i]] < 0){
			count++;
		}
	}
	if(!count){
		printf("Yes %d", len1 -len2);
	}
	else{
		printf("No %d", count);
	}
	return 0;
}

5、b1040

#include <cstdio>
#include <cstring>

const int MAXN = 100010;
const int MOD = 1000000007;
char str[MAXN];
int leftNumP[MAXN] = {0};

int main(){
	gets(str);
	int len = strlen(str);
	for(int i = 0; i < len; i++){
		if(i > 0){
			leftNumP[i] = leftNumP[i - 1];
		}
		if(str[i] == 'P'){
			leftNumP[i]++;
		}
	}
	int ans = 0, rightNumT = 0;
	for(int i = len - 1; i >= 0; i--){
		if(str[i] == 'T'){
			rightNumT++;
		}
		else if(str[i] == 'A'){
			ans = (ans + leftNumP[i] * rightNumT) % MOD;
		}
	}
	printf("%d", ans);
	return 0;
} 


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值