zoukankan      html  css  js  c++  java
  • A+B Coming

    Problem Description
    Many classmates said to me that A+B is must needs.
    If you can’t AC this problem, you would invite me for night meal. ^_^
     
    Input
    Input may contain multiple test cases. Each case contains A and B in one line.
    A, B are hexadecimal number.
    Input terminates by EOF.
     
    Output
    Output A+B in decimal number in one line.
     
    Sample Input
    1 9
    A B
    a b
     
    Sample Output
    10
    21
    21
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <ctype.h>
     4 #include <math.h>
     5 
     6 int decimal(char s[]);
     7 
     8 int main(){
     9     char s1[50];
    10     char s2[50];
    11     int number1;
    12     int number2;
    13     
    14     while(scanf("%s%s",s1,s2)!=EOF){
    15         number1=decimal(s1);
    16         number2=decimal(s2);
    17         
    18         printf("%d
    ",number1+number2);
    19         
    20     }
    21     
    22     return 0;
    23 }
    24 
    25 int decimal(char s[]){
    26     int result=0;
    27     int i;
    28     int length;
    29     int temp;
    30     
    31     length=strlen(s);
    32     
    33     for(i=length-1;i>=0;i--){
    34         if(isdigit(s[i]))
    35             temp=s[i]-'0';
    36             
    37         else if(s[i]=='A' || s[i]=='a')
    38             temp=10;
    39             
    40         else if(s[i]=='B' || s[i]=='b')
    41             temp=11;
    42             
    43         else if(s[i]=='C' || s[i]=='c')
    44             temp=12;
    45             
    46         else if(s[i]=='D' || s[i]=='d')
    47             temp=13;
    48             
    49         else if(s[i]=='E' || s[i]=='e')
    50             temp=14;
    51             
    52         else if(s[i]=='F' || s[i]=='f')
    53             temp=15;
    54             
    55         result+=temp*pow(16,length-1-i);
    56     }
    57     
    58     return result;
    59 }
  • 相关阅读:
    FastAdmin CMS 插件下载
    使用 Python 连接到 PADS Layout
    Javascript undefined 和 null
    反馈给又拍云需要以下信息
    Web前端性能优化之图片优化
    nodejs--实现跨域抓取数据
    HTML6 展望
    cSS3 伪类:nth-child 的使用方法
    css3中的几何图形shape研究
    iScroll5 API速查随记
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4086156.html
Copyright © 2011-2022 走看看