- 论坛徽章:
- 0
|
第一题:
//暂不考虑size <0
int power(int size,int base)
{
int i = 0;
int result = 1;
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
while(i < size)
{
result = result*base;
i++;
}
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
return result;
}
int strToInt(char *string)
{
int len = strlen(string);
int result = 0;
int i = 0;
if(string == NULL)
{
return -1;
}
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
printf("strlen(string)=%d\n",strlen(string));
printf("string=%s\n",string);
while(string[i] != '\0')
{
//'A'=65,26进制
result += (string[i]-64)*power(len - i - 1,26);
i++;
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
}
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
return result;
}
int main()
{
char str[4] = "ABC";
int result = 0;
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
result = strToInt(str);
printf("result=%d\n",result);
return 0;
} |
|