| ||||||||||
| 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<fstream>
#include<stdlib.h>
using namespace std;
long s[40001];
int main()
{
ifstream infile;
ofstream outfile;
infile.open("data.in",ios::in);
outfile.open("data.out",ios::out);
long k,i,t,n,temp,j,count,num,l,data[100];
long long ans=0;
s[1]=1;
for (k=2;k<=32000;k++)
{
if (k<10)
s[k]=s[k-1]+1;
if (k>=10&&k<100)
s[k]=s[k-1]+2;
if (k>=100&&k<1000)
s[k]=s[k-1]+3;
if (k>=1000&&k<10000)
s[k]=s[k-1]+4;
if (k>=10000&&k<100000)
s[k]=s[k-1]+5;
}
infile>>t;
for (i=1;i<=t;i++)
{
infile>>n;
ans=0;
k=1;
while(ans<n)
{
ans+=s[k];k++;
}
k--;
ans-=s[k];
ans=n-ans;
count=0;
j=1;
while(j<=k&&count<ans)
{
temp=j;l=0;
while(temp>0&&count<ans)
{temp/=10;l++;}
if (count+l<ans)
count+=l;
else
{num=j;break;}
j++;
}
memset(data,0,sizeof(data));
j=1;
while(num>0)
{data[j++]=num%10;num/=10;}
j--;
outfile<<data[j-(ans-count)+1]<<endl;
}
infile.close();
outfile.close();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator