文章
10
粉丝
17
获赞
0
访问
3.9k
#include<bits/stdc++.h>
using namespace std;
void f(char s[]){
char out[105];
int cnt = 0;
int sum = 0;
int len = strlen(s);
for(int i = 2;i < len; i++){
sum *= 16;
if('0' <= s[i] && s[i] <= '9'){
sum += (s[i] - '0');
}else if('a' <= s[i] && s[i] <= 'f'){
sum += (s[i] - 'a' + 10);
}else{
sum += (s[i] - 'A' + 10);
}
}
printf("%d\n", sum);
}
int main(){
cha...
登录后发布评论
这样子写为啥过不了啊
#include <bits/stdc++.h>
using namespace std;
void f(char s[]){
char out[105];
int ans=0;
int len=strlen(s);
for(int i=0;i<len;i++)
{
ans=ans*16;
if(s[i]>='0'&&s[i]<='9') ans+=(s[i]-'0');
else if('a' <= s[i] && s[i] <= 'f') ans += (s[i] - 'a' + 10);
else ans+=(s[i]-'A')+10;
}
printf("%d\n",ans);
}
int main() {
char s[105];
while (scanf("%s",s)!=EOF) {
f(s);
}
return 0;
}