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

Re:一个奇异的程序(G++可过)

Posted by john_uid at 2007-01-12 15:53:30 on Problem 1019
In Reply To:一个奇异的程序(G++可过) Posted by:pdfpdf at 2006-05-20 00:11:43
> 以下程序我原来没用long long,而是用了int和unsigned int,结果在Debug底下答案是对的,在Release底下i>189414495时答案错的离谱(N多0)。后来用了long long,用G++可以AC,但是C++就Compile Error.问哪位大虾可以将其小改一下使其用C++可以AC??
> #include<iostream>
> using namespace std;
> int main()
> {
> 	long long a[5]={0,45,9045,1395495,189414495};
> 	long long b[6]={0,1,11,192,2893,38894};
> 	long long c[6]={0,1,10,100,1000,10000};
> 	long long n,i;
>     for(cin>>n;n>0;n--)
> 	{
> 		cin>>i;
> 		long long j;
> 		for(j=1;i>a[j];++j); //判是几位数
> 		i-=a[j-1];
> 		long long s=b[j],f=c[j];
> 		for(;i>s;++f)
> 			s+=b[j]+(f-c[j]+1)*j;
> 		long long t=s-i;                                  
> 		for(;t>0;--f,t-=j)
> 			if(f<c[j])j--;                           
>         if(t!=0){
> 			f+=1; 
> 			if(f>c[j]*10-1)j++;              
>             t+=j;                             
> 			for(;t!=0;--t,f/=10);
> 		}
> 		cout<<f%10<<endl;
> 	}
> }

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