首页 技术 正文
技术 2022年11月16日
0 收藏 712 点赞 2,260 浏览 1240 个字

题目

题目地址:PAT 乙级 1044

思路

简单的进制转化问题,根据题意进行相应的进制转化即可,因为题目已经划定了数据的求解范围,甚至连进制转化中的循环都不需要,进行简单计算就可以得出结果;

但本题还是有坑,结果就在这个坑上栽了很多次;10进制化为13进制的过程中,对于可以被13整除的数,后面的0需要省略,而不能打印出来,例如对于13、26这样的数,最终输出的结果是tam、hel,而不是tam tret、hel tret;

代码

 #include <iostream>
#include <string>
#include <cmath>
using namespace std; const string gewei[] = { "tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
const string shiwei[] = { "###", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" }; void ten2tir(string str) {
int num = , D_val = ;
for (int i = ; i < str.size(); i++) {
num += (str[i] - ) * pow(, (str.size() - D_val));
D_val++;
}
if (num < )
cout << gewei[num] << endl;
else {
if (num % == )
cout << shiwei[num / ] << endl;
else
cout << shiwei[num / ] << ' ' << gewei[num % ] << endl;
}
} void tir2ten(string str) {
int loc_space = ;
int sum = ;
for (int i = ; i < str.size(); i++)
if (str[i] == ' ')
loc_space = i;
if (loc_space) {
string tmp;
tmp = str.substr(, loc_space);
for (int i = ; i < ; i++)
if (tmp == shiwei[i])
sum += i * ;
tmp = str.substr(loc_space + , str.size() - loc_space - );
for (int i = ; i <= ; i++)
if (tmp == gewei[i])
sum += i;
}
else {
for (int i = ; i < ; i++)
if (str == shiwei[i])
sum += i * ;
for (int i = ; i <= ; i++)
if (str == gewei[i])
sum += i;
}
cout << sum << endl;
} int main() {
int n = ;
string str;
cin >> n;
cin.ignore();
for (int i = ; i < n; i++) {
getline(cin, str);
if (isdigit(str[]))
ten2tir(str);
else
tir2ten(str);
} return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294