随笔 - 32  文章 - 2  trackbacks - 0
<2008年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用链接

留言簿(3)

随笔档案

文章档案

搜索

  •  

积分与排名

  • 积分 - 8416
  • 排名 - 1249

最新评论

阅读排行榜

评论排行榜

不需要使用字符串,用数学方法计算就可以了。

#include <iostream>
#include 
<math.h>
using namespace std;
int main(){
    
int test;
    scanf(
"%d",&test);
    
for (;test>0;--test) {
        unsigned 
long int n;
        scanf(
"%d",&n);
        unsigned 
long int now(0),i(0),last(0),m;
        
while (now<n) now+=last+=(int)log10(++i)+1;
        now
-=last;
        n
-=now;
        now
=0;
        i
=0;
        
while (now<n) now+=(int)log10(++i)+1;
        now
-=(int)log10(i)+1;
        n
-=now;
        
int j=(int)log10(i)+2;
        j
=j-n;
        
for (int k=1;k<j;++k) i/=10;
        printf(
"%d\n",i%10);
        }

    }

posted on 2008-04-13 11:14 Joseph 阅读(316) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理