将这段代码改成c语言代码:#include<iostream> #include<math.h> using namespace std; int main(void){ char ch[100]; char temp; int i=0; while(1){ cin>>temp; if(temp=='#') break; if(isxdigit(temp)){ ch[i]=temp; i++; } } printf("%s\n",ch); int sum[i]; int andsum=0;//总和 for(int j=(i-1),k=0;j>=0;j--,k++){ if(isalpha(ch[j])){ if(isupper(ch[j])){ ch[j]=tolower(ch[j]); } sum[j]=ch[j]-'0'; sum[j]-=39; }else{ sum[j]=ch[j]-'0'; } andsum+=(sum[j]*pow(16,k)); } cout<<andsum<<endl; return 0; }
时间: 2024-01-03 16:04:16 浏览: 53
#include <stdio.h>
#include <ctype.h>
#include <math.h>
int main(void) {
char ch[100];
char temp;
int i = 0;
while (1) {
scanf("%c", &temp);
if (temp == '#') break;
if (isxdigit(temp)) {
ch[i] = temp;
i++;
}
}
ch[i] = '\0';
printf("%s\n", ch);
int sum[i];
int andsum = 0;
for (int j = i - 1, k = 0; j >= 0; j--, k++) {
if (isalpha(ch[j])) {
if (isupper(ch[j])) {
ch[j] = tolower(ch[j]);
}
sum[j] = ch[j] - '0';
sum[j] -= 39;
} else {
sum[j] = ch[j] - '0';
}
andsum += (sum[j] * pow(16, k));
}
printf("%d\n", andsum);
return 0;
}
阅读全文