3. Getting a simple simulation algorithm (3)

1.B1018

#include<stdio.h> 
int change(char c){
	if(c == 'B')	return 0; 
	if(c == 'C')	return 1; 
	if(c == 'J')	return 2; 
}
int main(){
	char mp[3] = {'B','C','J'};
	int n;
	scanf("%d",&n);
	int timeA[3] = {0},timeB[3] = {0};
	int handA[3] = {0},handB[3] = {0}; 
	char c1,c2;
	int k1,k2;
	while(n--){
		getchar();
		scanf("%c %c",&c1,&c2);
		k1 = change(c1);
		k2 = change(c2);
		if((k1+1)%3 == k2){
			timeA[0]++;
			timeB[2]++;
			handA[k1]++;
		}else if(k1 == k2){
			timeA[1]++;
			timeB[1]++;
		}else{
			timeA[2]++;
			timeB[0]++;
			handB[k2]++;
		}
	}
	printf("%d %d %d\n",timeA[0],timeA[1],timeA[2]);
	printf("%d %d %d\n",timeB[0],timeB[1],timeB[2]);
	int id1 = 0,id2 = 0;
	for(int i = 0;i<3;i++){
		if(handA[i]>handA[id1])	id1 = i;
		if(handB[i]>handB[id2])	id2 = i;  
	}
	printf("%c %c\n",mp[id1],mp[id2]);
	return 0;
}

2.B1020

#include<stdio.h>
#include<algorithm>
using namespace std;
struct mooncake{
	double store;
	double sell;
	double price;
}cake[1010];
bool cmp(mooncake a,mooncake b){
	return a.price > b.price;
}
int main(){
	int n;
	double D;
	scanf("%d%lf",&n,&D);
	for(int i = 0;i<n;i++)
		scanf("%lf",&cake[i].store);
	for(int i = 0;i<n;i++){
		scanf("%lf",&cake[i].sell);
		cake[i].price = cake[i].sell/cake[i].store;
	}	
	sort(cake,cake+n,cmp);
	double ans = 0;
	for(int i = 0;i<n;i++){
		if(cake[i].store<=D){
			D-=cake[i].store;
			ans+=cake[i].sell;
		} else{
			ans+= cake[i].price*D;
			break;
		}
	}
	printf("%.2f",ans);
	return 0;
}

3.B1026

#include<stdio.h> 
int main(){
	int c1,c2;
	scanf("%d%d",&c1,&c2);
	int ans = c2 - c1;
	if(ans%100>=50)
		ans = ans/100 + 1;
	else
		ans = ans / 100;
	printf("%02d:%02d:%02d\n",ans/3600,ans%3600/60,ans%60);
	return 0;
}

4.B1032

#include<stdio.h>
const int max = 100010;
int school[max] = {0};
int main(){
	int n,num,score;
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d%d",&num,&score);
		school[num]+=score;
	}
	int k = 1,MAX = -1; 
	for(int i = 1;i<=n;i++){
		if(MAX<school[i]){
			MAX = school[i];
			k = i;
		}
	}		
	printf("%d %d",k,MAX);
	return 0;
}

5.B1040 A1093

#include<stdio.h>
#include<string.h>
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\n",ans);
	return 0;
}

6.B1046

#include<stdio.h> 
int main(){
	int n;
	scanf("%d",&n);
	int a3 = 0,b3 = 0;
	while(n--){
		int a1,a2,b1,b2;
		scanf("%d%d%d%d",&a1,&a2,&b1,&b2);
		if(a1+b1 == a2 && a1+b1 != b2)
			b3++;
		else if(a1+b1 != a2 && a1+b1 == b2)
			a3++;
	}
	printf("%d %d\n",a3,b3);
	return 0;
}
Published 26 original articles · won praise 3 · Views 194

Guess you like

Origin blog.csdn.net/qq_41898248/article/details/104051521