zoukankan      html  css  js  c++  java
  • 【PAT甲级】1027 Colors in Mars (20 分)

    题意:

    输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出。

    AAAAAccepted code:

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 char ans[5][5];
     5 int main(){
     6     int a,b,c;
     7     cin>>a>>b>>c;
     8     int cnt=0;
     9     while(a){
    10         int x=a%13;
    11         if(x==10)
    12             ans[1][++cnt]='A';
    13         else if(x==11)
    14             ans[1][++cnt]='B';
    15         else if(x==12)
    16             ans[1][++cnt]='C';
    17         else
    18             ans[1][++cnt]=x+'0';
    19         a/=13;
    20     }
    21     if(cnt==0)
    22         ans[1][1]='0',ans[1][2]='0';
    23     else if(cnt==1)
    24         ans[1][2]='0';
    25     cnt=0;
    26     while(b){
    27         int x=b%13;
    28         if(x==10)
    29             ans[2][++cnt]='A';
    30         else if(x==11)
    31             ans[2][++cnt]='B';
    32         else if(x==12)
    33             ans[2][++cnt]='C';
    34         else
    35             ans[2][++cnt]=x+'0';
    36         b/=13;
    37     }
    38     if(cnt==0)
    39         ans[2][1]='0',ans[2][2]='0';
    40     else if(cnt==1)
    41         ans[2][2]='0';
    42     cnt=0;
    43     while(c){
    44         int x=c%13;
    45         if(x==10)
    46             ans[3][++cnt]='A';
    47         else if(x==11)
    48             ans[3][++cnt]='B';
    49         else if(x==12)
    50             ans[3][++cnt]='C';
    51         else
    52             ans[3][++cnt]=x+'0';
    53         c/=13;
    54     }
    55     if(cnt==0)
    56         ans[3][1]='0',ans[3][2]='0';
    57     else if(cnt==1)
    58         ans[3][2]='0';
    59     cout<<"#"<<ans[1][2]<<ans[1][1]<<ans[2][2]<<ans[2][1]<<ans[3][2]<<ans[3][1];
    60     return 0;
    61 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    面向过程,面向对象三大特性
    JDBC连接数据库
    java线程
    ssm
    com组件方面的书籍
    剑雨
    JavaScript为元素动态添加事件之(attachEvent||addEventListener)
    Opacity多浏览器透明度兼容处理
    通过U盘安装Windows 7
    蜀门Online 简单打怪脚本(vbs)
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11481899.html
Copyright © 2011-2022 走看看