| ||||||||||
| 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 | |||||||||
一个奇异的程序(G++可过)以下程序我原来没用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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator