题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1647
题意:求一个在无限规律递增的序列位置上的数 序列递增遵循 112 123 1234 12345 123456的规律
思路:刚开始以为位置上的数可以是多位的 比如11什么的,结果真的是"位"!。有多种解决方法啦,计算位置什么的 构造串
AC代码:
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
string t;
int main()
{
int T;
cin>>T;
while(T--){
t.clear();
int pos,n=1;
cin>>pos;
t="1";
while(pos>t.size()){
pos-=t.size();
char temp[10];
sprintf(temp,"%d",++n);
t+=temp;
}
cout<<t[pos-1]<<endl;
}
return 0;
}