PAT (Basic) 1016~1020

1016. 部分A+B (15)

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string a, b;
	int da, db;
	int pa = 0, pb = 0;
	cin >> a >> da >> b >> db;

	int len1 = a.length();
	int len2 = b.length();

	for (int i = 0; i < len1; i++)
	{
		if (a[i] - '0' == da)
		{
			pa *= 10;
			pa += da;
		}
	}
	for (int i = 0; i < len2; i++)
	{
		if (b[i] - '0' == db)
		{
			pb *= 10;
			pb += db;
		}
	}
	cout << pa + pb << endl;

	return 0;
}

1017. A除以B (20)

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string a;
	int b;
	cin >> a >> b;
	vector<int> q;
	
	if (a.length() == 1)
	{
		if (a[0] - '0' < b)
		{
			cout << "0 " << a[0] - '0' << endl;
		}
		else if (a[0] - '0' >= b)
		{
			cout << "1 " << a[0] - '0' - b << endl;
		}
	}
	else
	{
		int tmpa = (a[0] - '0') * 10 + a[1] - '0';
		q.push_back(tmpa / b);
		int tmpr = tmpa % b;
		for (int i = 2; i < a.length(); i++)
		{
			tmpa = tmpr * 10 + a[i] - '0';
			q.push_back(tmpa / b);
			tmpr = tmpa % b;
		}
		vector<int> ::iterator it;
		for (it = q.begin(); it != q.end(); ++it)
			cout << *it;
		cout << " " << tmpr << endl;
	}
	return 0;
}

1018. 锤子剪刀布 (20)

#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	char c1, c2;
	int win = 0, tie = 0, fail = 0;
	int winc1 = 0, winj1 = 0, winb1 = 0;
	int winc2 = 0, winj2 = 0, winb2 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> c1 >> c2;
		if (c1 == c2)
		{
			tie++;
		}
		else if (c1 == 'C' && c2 == 'J')
		{
			win++;
			winc1++;
		}
		else if (c1 == 'C' && c2 == 'B')
		{
			fail++;
			winb2++;
		}
		else if (c1 == 'J' && c2 == 'C')
		{
			fail++;
			winc2++;
		}
		else if (c1 == 'J' && c2 == 'B')
		{
			win++;
			winj1++;
		}
		else if (c1 == 'B' && c2 == 'C')
		{
			win++;
			winb1++;
		}
		else if (c1 == 'B' && c2 == 'J')
		{
			fail++;
			winj2++;
		}
	}
	cout << win << " " << tie << " " << fail << endl;
	cout << fail << " " << tie << " " << win << endl;
	if (winb1 >= winc1 && winb1 >= winj1)
		cout << "B";
	else if (winc1 > winb1 && winc1 >= winj1)
		cout << "C";
	else if (winj1 > winb1 && winj1 > winc1)
		cout << "J";
	cout << " ";
	if (winb2 >= winc2 && winb2 >= winj2)
		cout << "B";
	else if (winc2 > winb2 && winc2 > winj2)
		cout << "C";
	else if (winj2 > winb2 && winj2 > winc2)
		cout << "J";
	cout << endl;

	return 0;
}

1019. 数字黑洞 (20)

同PAT-A-1069. The Black Hole of Numbers (20) 见: http://blog.csdn.net/hale1007/article/details/20251397

1020. 月饼 (25)

同PAT-A-1070. Mooncake (25) 见:http://blog.csdn.net/hale1007/article/details/20455225
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值