pat basic 1044

Posted miao-xixixi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pat basic 1044相关的知识,希望对你有一定的参考价值。

题目如下:

技术图片

 

 思路:

(1)题目的意思:让我们把十进制转化为十三进制,再把十三进制转化为十进制

(2)需要注意的是,如果转化为十三进制的时候 eg;input 26(13的倍数),那么十三进制为10,重点来了这个时候不是让你输入一零 

  而是让你输入是十,也就是只输入高位就可以了

代码如下:

#include<cstdio> 
#include<sstream>
#include<iostream>
#include<cstring>
#include<unordered_map>
#include<array>
using namespace std;
main(){
    int n;
    array<string,13> low={"tret","jan","feb","mar","apr","may","jun","jly", "aug", "sep", "oct", "nov","dec"};
    array<string,13> high={"tret","tam", "hel", "maa", "huh", "tou", "kes","hei","elo","syy","lok","mer", "jou"};
//    array<int,13> temp;
    unordered_map<string,int> temp;
    for(int i=0;i<13;i++)
    {   temp[low[i]]=i;
        temp[high[i]]=i*13;
    }
    cin>>n;
    string b="";
    cin.get();
    while(n--){
        getline(cin,b);
        if(isdigit(b[0]))
        { int c=stoi(b);
            if(c/13!=0&&c%13!=0)
            cout<<high[c/13]<<" ";
            else if(c/13!=0&&c%13==0)
            cout<<high[c/13]<<endl;
             if(c/13==0||c%13!=0)
            cout<<low[c%13]<<endl;
        }
        else{
            stringstream a;
            a<<b;
            int k=0;
            while(a>>b){
            k+=temp[b];
            }
            cout<<k<<endl;
        }
    }
    
    return 0;
}

 另外:

如何把字符流中 a空格b转化为ab?

代码如下:

#include<cstdio>
#include<sstream>
#include<iostream>
using namespace std;
main(){
    string n;
    getline(cin,n);
    cout<<n<<endl;
    stringstream s;
    s<<n;     
    while(s>>n)
    cout<<n<<endl;
    //将a b分开能转换为ab 
    
    char a;
    while(cin>>a) 
    cout<<a;
    return 0;
}

 

以上是关于pat basic 1044的主要内容,如果未能解决你的问题,请参考以下文章

(Python) PAT(Basic Level) Practice 刷题笔记(34-66)

PAT Basic 1049

(Python) PAT(Basic Level) Practice 刷题笔记(34-66)

PAT Basic 1078

PAT甲级1044

PAT乙级1044