PAT B1014/A1061 福尔摩斯的约会(20)
书中AC代码
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
char week[7][5] = {
"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"
};
char str1[70], str2[70], str3[70], str4[70];
cin.getline(str1, 70);
cin.getline(str2, 70);
cin.getline(str3, 70);
cin.getline(str4, 70);
// gets(str1);
// gets(str2);
// gets(str3);
// gets(str4);
int len1 = strlen(str1);
int len2 = strlen(str2);
int len3 = strlen(str3);
int len4 = strlen(str4);
int i;
//寻找str1和str2中第一对相同位置的A~G的大写字母
for(i = 0; i < len1 && i < len2; i++) {
if(str1[i] == str2[i] && str1[i] >= 'A' && str1[i] <= 'G') {
printf("%s ", week[str1[i] - 'A']);
break;
}
}
for(i++; i < len1 && i < len2; i++) {
if(str1[i] == str2[i]) {
if(str1[i] >= '0' && str1[i] <= '9') {
printf("%02d:", str1[i] - '0');
break;
} else if(str1[i] >= 'A' && str1[i] <= 'N') {
printf("%02d:", str1[i] - 'A' + 10);
break;
}
}
}
for(i = 0; i < len3 && i <len4; i++) {
if(str3[i] == str4[i]) {
if((str3[i] >= 'A' && str3[i] <= 'Z') || (str3[i] >= 'a' && str3[i] <= 'z')) {
printf("%02d", i);
break;
}
}
}
return 0;
}
自己写的,有一个没有AC,找不到哪里出错
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
//char DD; //日期
#endif // ONLINE_JUDGE
int DD = 0, HH = 0, MM = 0;//小时,分钟
char week[7][5] = {
"MON", "THU", "WED", "THU", "FRI", "SAT", "SUN"
};
char temp[4][70] = {0};
int len[4] = {0};
for(int i = 0; i < 4; i++) {
cin.getline(temp[i], 70);
len[i] = strlen(temp[i]);
//for(int j = 0; j < len[i]; j++) printf("")
}
// for(int i = 0; i < 4; i++) {
// printf("len: %d, string: %s\n", len[i], temp[i]);
//
// }
int smalllen = 0;
if(len[0] < len[1]) smalllen = len[0];
else smalllen = len[1];
int t = 0;
int i = 0;
for(i = 0; i < smalllen; i++) { //查找日期
if(temp[0][i] == temp[1][i]) {
if('A' <= temp[0][i] && 'G' >= temp[0][i]) {
// printf("temp[0][%d]:%c\n", i, temp[0][i]);
DD = temp[0][i] - 'A';
// printf("DD:%d\n", DD);
break;
}
}
}
for(i++; i < smalllen; i++) { //在上面的基础再往后搜索小时
if(temp[0][i] == temp[1][i]) {
if('0' <= temp[0][i] && '9' >= temp[0][i]) {
HH = temp[0][i] - '0';
// printf("temp[0][%d]:%c\n", i, temp[0][i]);
// printf("HH:%d\n", HH);
break;
} else if('A' <= temp[0][i] && 'N' >= temp[0][i]) {
HH = temp[0][i] - 'A' + 10;
// printf("temp[0][%d]:%c\n", i, temp[0][i]);
// printf("HH:%d\n", HH);
break;
}
}
}
smalllen = 0;
if(len[2] < len[3]) smalllen = len[2];
else smalllen = len[3];
for(int i = 0; i < smalllen; i++) {
if(temp[2][i] == temp[3][i]) {
if(('A' <= temp[2][i] && 'Z' >= temp[2][i]) || ('a' <= temp[2][i] && 'z' >= temp[2][i])) {
// printf("temp[2][%d]:%c\n", i, temp[0][i]);
MM = i;
// printf("MM:%d\n", MM);
break;
}
}
}
printf("%s %02d:%02d", week[DD], HH, MM);
return 0;
}
PAT B1014/A1061 福尔摩斯的约会(20)的更多相关文章
- PAT乙级 1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大侦探福尔摩斯接到一张奇怪的 ...
- PAT 乙级 1014 福尔摩斯的约会 (20) C++版
1014. 福尔摩斯的约会 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大侦探福尔摩斯接到一张奇怪的 ...
- 【PAT】1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hy ...
- PAT Basic 1014 福尔摩斯的约会 (20 分)
大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...
- PAT Basic 1014 福尔摩斯的约会 (20 分) Advanced 1061 Dating (20 分)
大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...
- PAT乙级:1014 福尔摩斯的约会 (20分)
PAT乙级:1014 福尔摩斯的约会 (20分) 题干 大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk ...
- 浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT 1014 福尔摩斯的约会 (20)(代码+思路)
1014 福尔摩斯的约会 (20)(20 分) 大侦探福尔摩斯接到一张奇怪的字条:"我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfd ...
- PAT (Basic Level) Practise (中文)- 1014. 福尔摩斯的约会 (20)
http://www.patest.cn/contests/pat-b-practise/1014 1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 ...
随机推荐
- Linux+CLion+树莓派远程编译时,Cmake编译出现undefined reference to `vtable for MainWindow'的解决办法
在win+CLion上进行远程qt开发时碰到以下错误: 错误提示: undefined reference to `vtable for MainWindow' 原因:源文件的目录结构有问题?? 解决 ...
- BUUCTF平台-web-边刷边记录-2
1.one line tool <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $_SERVER['REMOTE_ADDR'] = $_ ...
- js毫秒数转换为具体日期
[1].毫秒数转换为具体日期 function getMyDate(str) { var oDate = new Date(str), oYear = oDate.getFullYear( ...
- 树形dp(灯与街道)
https://cn.vjudge.net/contest/260665#problem/E 题意: 给你一个n个点m条边的无向无环图,在尽量少的节点上放灯,使得所有边都被照亮.每盏灯将照亮以它为一个 ...
- legend3---15、像粉丝数、关注数、课程数等数量数据如何处理
legend3---15.像粉丝数.关注数.课程数等数量数据如何处理 一.总结 一句话总结: 在主表中加入这种数量字段:比如在用户表中加入粉丝数,关注数字段 普通更新:增加数量的时候将数据插入到关联表 ...
- babel 实践
一.@babel/core var babel = require("@babel/core");babel.transform(code, options, function(e ...
- EBR-TLV数据格式
EMV规范中的BER-TLV数据格式:BER-TLV结构由Tag.Length.Value三部分组成. [TAG域]TAG可以由1个与多个字节组成,TAG域的第一个字节编码格式如下: 其中由三部分组成 ...
- BCNF/3NF的判断方法
判断是否是 3NF 的条件: 对于 R 上的每个函数依赖 X->A (X 是关系 R 属性的一个子集,A 是 R 的一个属性) ,以下条件中的一个成立:1 X ∈ A2 X 是超码3 A 是 R ...
- 一百零六:CMS系统之修改邮箱功能完成
这里采用把验证码放到memcached中,所以封装一个memcached的操作 import memcache cache = memcache.Client(['127.0.0.1:11211'], ...
- dede不同栏目调用不同banner图的方法
用顶级栏目ID 方法: <img src="{dede:global.cfg_templets_skin/}/images/{dede:field.typeid function=&q ...