Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

附代码吧!很简单的做法!!!嘎嘎

Posted by chenxuan123456789 at 2012-11-11 11:30:43 on Problem 1131
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator