标签:des style blog io color ar os sp for
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 long long mul(int n)//要用long long类型 7 { 8 long long s=1; 9 for(int i=1;i<=n;i++) 10 s*=16; 11 return s; 12 } 13 14 int main() 15 { 16 long long a=0; 17 char str[9]; 18 cin>>str; 19 for(int i=0;i<strlen(str);++i) 20 { 21 int temp; 22 if(str[i]>=‘0‘&&str[i]<=‘9‘) 23 temp=str[i]-‘0‘; 24 else 25 temp=str[i]-55; 26 a+=(temp*mul(i)); 27 } 28 cout<<a; 29 return 0; 30 }
这样就对了
1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 using namespace std; 5 6 long long mul(int n)//要用long long类型 7 { 8 long long s=1; 9 for(int i=1;i<=n;i++) 10 s*=16; 11 return s; 12 } 13 14 int main() 15 { 16 long long a=0; 17 string str; 18 cin>>str; 19 reverse(str.begin(),str.end()); 20 for(int i=0;i<str.length();++i) 21 { 22 int temp; 23 if(str[i]>=‘0‘&&str[i]<=‘9‘) 24 temp=str[i]-‘0‘; 25 else 26 temp=str[i]-55; 27 a+=(temp*mul(i)); 28 } 29 cout<<a; 30 return 0; 31 }
标签:des style blog io color ar os sp for
原文地址:http://www.cnblogs.com/wpnan/p/4095789.html