PTA火星番号(20ポイント)

無限の光を放つのは人間の心であり、無限の闇を生み出すのも人間の心であり、光と闇が絡み合って戦うこの世界は、懐かしくて無力な世界です。

火星の人々は、ベース13で数を数えます:

  • 地球上のゼロは火星では「トレット」と呼ばれます。
  • 地球上の1〜12の数字は、それぞれ火星では「1月、2月、3月、4月、5月、6月、jly、8月、9月、10月、11月、12月」と呼ばれます。
  • 次の上位の桁では、火星の人々は12の数字をそれぞれ「タム、ヘル、マー、ハァ、トゥー、ケス、ヘイ、エロ、syy、ロック、マー、ジュー」と名付けています。

たとえば、地球上の番号29は、火星では「ヘルマール」と呼ばれます。火星の「elo nov」は地球の115に対応します。これらの2つの惑星の人々の間のコミュニケーションを助けるために、地球と火星の数体系間の相互変換のためのプログラムを書くことになっています。

入力仕様:

各入力ファイルには1つのテストケースが含まれています。いずれの場合も、最初の行には正の整数N(<100)が含まれています。次に、N本の線が続き、それぞれが[0、169)の数値を含み、地球番号または火星の番号のいずれかで示されます。

出力仕様:

番号ごとに、対応する他の言語の番号を1行に印刷します。

入力例:

4
29
5
elo nov
tam

出力例:

hel mar
may
115
13
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX

//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=3e5+10;
string a[13]={"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13]={" ", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string n;
void fman(int num){ 
    if (num>=13){
        if(num%13==0) 
			cout<<b[num/13];
        else 
			cout<<b[num/13]<<" "<<a[num%13];
    }
    else 
		cout<<a[num];
}
void ftian(){
    int t1=0, t2=0;
    string s1=n.substr(0, 3), s2;
    if (n.length()>4) 
		s2=n.substr(4, 3);
    for (int j=1; j<=12; j++) {
        if (s1==b[j]) 
			t1=j;
        if (s1==a[j]||s2==a[j]) 
			t2=j;  
    }
    cout<<t1*13+t2;
}
int main() {
    int x;
    cin>>x;
    getchar();
    for (int i=0; i<x; i++) {
        getline(cin, n);
        if (n[0]>='0'&&n[0]<='9')
            fman(stoi(n));
        else
            ftian();
        cout<<endl;
    }
    return 0;
}

 

おすすめ

転載: blog.csdn.net/weixin_44170305/article/details/108430014