poj2719--Faulty Odometer(简单进制转化)
先把大于4的数自减1,然后把这个9进制的数转化为10进制输出
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //Accepted 164K 47MS C++ 413B 2 #include <stdio.h> 3 #include <string.h> 4 5 int solve(char s[]) 6 { 7 int ans = 0; 8 int t = 1; 9 for(int i = strlen(s) - 1; i >= 0 ;i--) 10 { 11 ans += (s[i] - '0') * t; 12 t *= 9; 13 } 14 return ans; 15 } 16 int main(void) 17 { 18 char s[20]; 19 while(scanf("%s",s)!=EOF && strcmp(s,"0") != 0) 20 { 21 printf("%s",s); 22 for(int i=0;i<strlen(s);i++) 23 if(s[i] > '4') s[i]--; 24 printf(": %d\n",solve(s)); 25 } 26 return 0; 27 }