【PAT甲】A1011/A1006

22 篇文章 0 订阅
/*
*时间:2018年4月22日20:31:13-2018年4月22日20:56:27
*题目:1011.World Cup Betting
*分数:20
*编译器:g++
*题目描述:
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players
 from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting
 their money where their mouths were, by laying all manner of World Cup bets.

Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. 
Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. There was an
 odd assigned to each result. The winner's odd would be the product of the three odds times 65%.

For example, 3 games' odds are given as the following:

 W    T    L
1.1  2.5  1.7
1.2  3.0  1.6
4.1  1.2  1.1

To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans,
 then the maximum profit would be (4.1*3.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal places).

Input

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct
 odds corresponding to W, T and L.

Output

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and 
the number must be separated by one space.
Sample Input

1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

Sample Output

T T W 37.98
*/

//思路:注意小数点后保留两位,四舍五入
#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
	double profit[3][3];
	double beilvMax[3] = {0};
	for (int i=0; i<3; i++)
	{
		int mark = 0;
		cin>>profit[i][0]>>profit[i][1]>>profit[i][2];
		for (int j=0; j<3; j++)
		{
			if(profit[i][j] > beilvMax[i])
			{
				beilvMax[i] = profit[i][j];
				mark = j; //mark 0、1、2分别表示W、T、L
			}
		}	
		if (mark == 0) cout<<"W ";
		else if (mark == 1) cout<<"T ";
		else cout<<"L ";
	}
	//四舍五入处理
	double Profit = (double)(beilvMax[0] * beilvMax[1] * beilvMax[2] * 0.65 - 1) * 2;//计算盈利值
	if (Profit*100 - int(Profit*100) >= 0.5) Profit += (double)0.01;//因为要比较小数点后第三位是否大于五,一般方法不太好比较
	printf("%.2f", Profit);                                         //我是先把数放大100,double类型的这个数减去int类型看是否大于0.5即可。
		
	return 0;
}



/*
*时间:2018年4月22日20:57:50-2018年4月22日21:19:56
*题目:1006.Sign In and Sign Out
*分数:25
*编译器:g++
*题目描述:
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who 
signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked 
and locked the door on that day.

Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, 
which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID
 numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person,
 and there are no two persons sign in or out at the same moment.
Sample Input:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output:

SC3021234 CS301133
*/
//思路:一开始自己想的不简便,没有用sort函数,写着写着发现写的麻烦了,还不如写两个sort的cmp比较快捷
//数据读进来后分别比较sign in 的最早时间按升序排一次,输出stu[0].ID
//再比较sign out 的最迟时间,按降序排一次,输出stu[0].ID
#include <iostream>
using namespace std;
#include <string.h>
#include <algorithm>
#include <stdio.h>
struct student//定义每个人的一个结构体
{
	string ID;
	int sign_in[3];
	int sign_out[3];
};
bool cmp_sign_in(student a, student b)//unlock time cmp
{
	if (a.sign_in[0] != b.sign_in[0]) return (a.sign_in[0] < b.sign_in[0]);
	else if (a.sign_in[1] != b.sign_in[1]) return (a.sign_in[1] < b.sign_in[1]);
	else return (a.sign_in[2] < b.sign_in[2]);	
}
bool cmp_sign_out(student a, student b)//lock time cmp
{
	if (a.sign_out[0] != b.sign_out[0]) return (a.sign_out[0] > b.sign_out[0]);
	else if (a.sign_out[1] != b.sign_out[1]) return (a.sign_out[1] > b.sign_out[1]);
	else return (a.sign_out[2] > b.sign_out[2]);	
}
int main()
{
	int N;
	cin>>N;
	student stu[N];
	for (int i=0; i<N; i++)
	{
		cin>>stu[i].ID;
		scanf("%d:%d:%d",&stu[i].sign_in[0], &stu[i].sign_in[1], &stu[i].sign_in[2]);//scanf就是好用,千万记得加&
		scanf("%d:%d:%d",&stu[i].sign_out[0], &stu[i].sign_out[1], &stu[i].sign_out[2]);
	}
	sort(stu, stu+N, cmp_sign_in);//sign in 升序
	cout<<stu[0].ID<<" ";
	sort(stu, stu+N, cmp_sign_out);//sign out 降序
	cout<<stu[0].ID;
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值