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 |
搞不清楚我这段代码哪里会WA,请教#include <cstdio> #include <cstring> using namespace std; int log10(int n) { if(n<10)return 0; if(n<100)return 1; if(n<1000)return 2; if(n<10000)return 3; return 4; } int pow10(int n) { if(n==0)return 1; if(n==1)return 10; if(n==2)return 100; if(n==3)return 1000; if(n==4)return 10000; } long width(int n) { long r=0; for(int i=1;i<=log10(n);i++) { r+=9*long(pow10(i-1))*i; } r+=(n-pow10(log10(n))+1)*(log10(n)+1); return r; } int main() { int n; scanf("%d",&n); long m[n]; for(int i=0;i<n;i++) { scanf("%d",&m[i]); for(int j=i-1;m[j+1]<m[j]&&j>=0;j--) { long t=m[j+1]; m[j+1]=m[j]; m[j]=t; } } unsigned long k=0; int p=0; for(int j=1;;j++) { long w=width(j); long w2=w; while(k+w2>=m[p]) { w=w2; for(int i=j;i>0;i--) { char a[20]; sprintf(a,"%d",i); w-=strlen(a); if(k+w<m[p]) { printf("%c\n",a[m[p]-k-w-1]); break; } } p++; if(p==n)goto ending; } k+=w2; } ending: return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator