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 |
附代码吧!很简单的做法!!!嘎嘎#include <iostream> #include <string.h> using namespace std; char str[100],res[100],ans[100]; bool judge(int s,int index) { for(int i=s;i<index;i++) if(res[i]!='0') return false; return true; } int main() { int i,index,k,length,m,j,n; while(cin>>str) { cout<<str<<" [8] = "; length=strlen(str); index=length-1; memset(res,'0',sizeof(res)); m=0; for(;index>1;index--) { res[0]=str[index]; i=0; k=res[0]-'0'; while(1) { ans[i++]=k/8+'0'; k%=8; k=10*k+(res[i]-'0'); if(judge(i,n)&&index!=length-1&&!k) break; if(index==length-1&&!k) break; } n=i; for(j=0;j<i;j++) res[j]=ans[j]; } ans[j]='\0'; length=strlen(ans); for(j=0;j<length;j++) { if(j==1) cout<<'.'; cout<<ans[j]; } cout<<" [10]"<<endl; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator