hdoj 1720(不解释)

来源:互联网 发布:网络协议为什么要分层 编辑:程序博客网 时间:2024/05/17 23:49
#include<iostream>#include<stdio.h>#include<string>#include<math.h>//#define MAX 2000#define MAX 10using namespace std;int getChar(char x){//10以内if(x-'0'<10)return (x-'0');if(x-'a'>=0&&x-'a'<6){return (x-'a'+10);}if(x-'A'>=0&&x-'A'<6){return (x-'A'+10);}return 0;}int getString(char hex[]){int sum=0;//首先逆序char temp[MAX];int i=0;for(i=0;i<strlen(hex);i++){temp[i]=hex[strlen(hex)-i-1];}temp[strlen(hex)]='\0';//开始计算for(i=0;i<strlen(hex);i++){sum+=getChar(temp[i])*pow(16,i);}return sum;}int main(){//freopen("in.txt","r",stdin);char a[MAX];char b[MAX];while(scanf("%s",a)!=EOF){scanf("%s",b);cout<<getString(a)+getString(b)<<endl;}return 0;}

原创粉丝点击