Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:who can help me,I am a newhand!In Reply To:who can help me,I am a newhand! Posted by:kuangwenkui at 2007-06-20 20:47:05 算法: 1.把九进制转化为十进制 2.由于每一位都把4跳过了,要先把字符串的每一位完全转化为九进制才行 方法:如果a[j] >= '4',n = a[j] - '1';否则n = a[j] - '0'; 然后sum += (int)( n * pow( 9.0, len - j - 1)); #include<stdio.h> #include<string.h> #include<math.h> int _tmain(int argc, _TCHAR* argv[]) { char a[10000]; int i,j,n, len; long sum; sum=0; for(i=0; ;i++) { scanf("%s",a); if(a[0]=='0') break; len=strlen(a); for( j = 0; j < len; j++) { if(a[j] >= '4') n = a[j] - '1'; else n = a[j] - '0'; sum += (int)( n * pow( 9.0, len - j - 1)); } printf("%s: %d\n",a,sum); sum = 0; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator