PAT甲级1060,1061解题报告

49 篇文章 0 订阅
47 篇文章 0 订阅

1060 Are They Equal (25 point(s))

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10​5​​ with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine.

Input Specification:

Each input file contains one test case which gives three numbers N, A and B, where N (<100) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 10​100​​, and that its total digit number is less than 100.

Output Specification:

For each test case, print in a line YES if the two numbers are treated equal, and then the number in the standard form 0.d[1]...d[N]*10^k (d[1]>0 unless the number is 0); or NO if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.

Note: Simple chopping is assumed without rounding.

Sample Input 1:

3 12300 12358.9

Sample Output 1:

YES 0.123*10^5

Sample Input 2:

3 120 128

Sample Output 2:

NO 0.120*10^3 0.128*10^3

题目大意:告诉一个机器的精度,和两个数字,问这两个数字在机器上的表示是不是一样。

解题思路:水题。。就是用字符串处理考虑清楚几种情况就行了,没什么讲究的。。但我第一发交上去WA了一片哈哈,因为我YES打成了Yes。

代码如下:

#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<list>
#include<climits>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<string>
using namespace std;
string getres(string s,int &Pos,int re){
	int tmp = 0;
	while (s.size() > 0 && s[0] == '0')s.erase(s.begin());
	if (s[0] != '.') {
		while (tmp < s.size() && s[tmp] != '.') {
			tmp++;
			Pos++;
		}
		if (tmp < s.size()) {
			s.erase(s.begin() + tmp);
		}
	}
	else {
		s.erase(s.begin());
		while (s.size() > 0 && s[0] == '0') {
			s.erase(s.begin());
			Pos--;
		}
	}
	if (s.size() == 0)Pos = 0;
	tmp = 0;
	string res="";
	for(int i=0;i<re;i++)
	{
		if (tmp < s.size())
			res += s[tmp++];
		else
			res += '0';
	}
	return res;
}
int main() {
	int n;
	string a, b;
	cin >> n >> a >> b;
	int ea = 0, eb = 0;
	string resa = getres(a, ea, n);
	string resb = getres(b, eb, n);
	if (resa == resb&&ea == eb) 
		cout << "YES 0." << resa << "*10^" << ea << endl;	
	else
		cout << "NO 0." << resa << "*10^" << ea << " 0." << resb << "*10^" << eb << endl;
	return 0;
}

1061 Dating (20 point(s))

Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

Input Specification:

Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.

Output Specification:

For each test case, print the decoded time in one line, in the format DAY HH:MM, where DAYis a 3-character abbreviation for the days in a week -- that is, MON for Monday, TUE for Tuesday, WED for Wednesday, THU for Thursday, FRI for Friday, SAT for Saturday, and SUN for Sunday. It is guaranteed that the result is unique for each case.

Sample Input:

3485djDkxh4hhGE 
2984akDfkkkkggEdsb 
s&hgsfdk 
d&Hyscvnm

Sample Output:

THU 14:04

题目大意:给定一个获取信息的规则,模拟这个规则获得信息。

规则如下:

四个字符串,第一二个字符串,第一个相同的大写字母,依次获取星期几。

第二个相同的大写字母或者0-9的数字,获取小时

第三四个字符串,第一个相同的字母,获取位置为分钟。

解题思路:也是水题。。虽然我也WA了几发,就是星期几的时候,注意范围,不要直接判断一下是不是大写字母,超过G的字母其实是没有意义的。还有就是注意break别忘了,我看了10几分钟才发现。

#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<list>
#include<climits>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#include<string>
using namespace std;
int main() {
	string a, b, c, d;
	getline(cin, a);
	getline(cin, b);
	getline(cin, c);
	getline(cin, d);
	int len1 = min(a.size(), b.size());
	int tmp=-1;
	for (int i = 0; i < len1; i++) {
		if (a[i] == b[i]&&a[i]>='A'&&a[i]<='G') {
			switch (a[i])
			{
			case 'A':cout << "MON "; break;
			case 'B':cout << "TUE "; break;
			case 'C':cout << "WED "; break;
			case 'D':cout << "THU "; break;
			case 'E':cout << "FRI "; break;
			case 'F':cout << "SAT "; break;
			case 'G':cout << "SUN "; break;
			default:
				break;
			}
			tmp = i;
			break;
		}
	}
	if (tmp != -1) {
		for (int i = tmp + 1; i < len1; i++) {
			if (a[i] == b[i] && ((a[i] >= 'A'&&a[i] <= 'N') || (a[i] >= '0'&&a[i] <= '9'))) {
				if (a[i] >= '0'&&a[i] <= '9') {
					cout << "0" << a[i];
					break;
				}
				else if ((a[i] >= 'A'&&a[i] <= 'N')) {
					int res = a[i] - 'A' + 10;
					cout << res;
					break;
				}
			}
		}
	}
	int len2 = min(c.size(), d.size());
	int t;
	for (int i = 0; i < len2; i++) {
		if (c[i] == d[i] && ((c[i] >= 'A'&&c[i] <= 'Z') || (c[i] >= 'a'&&c[i] <= 'z'))) {
			t = i;
			break;
		}
	}
	printf(":%02d\n", t);
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值