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;
}
无聊就学习 反正没事干
原文地址:https://www.cnblogs.com/miao-xixixi/p/12685456.html