Use stringstream to build the line , then cout the str[n-1]
#include
#include
#include
#include
using namespace std;
int main()
{
int n;
string line = "12345678910111213141516171819", str;
scanf("%d", &n);
for(int i = 20; i <= 500; i++){
stringstream ss;
ss<<i; ss>>str;
line += str;
//str.clear();
}
cout<<line[n-1];
/*please ignore the follow code
if(n <= 9) printf("%d", n); else if(n > 9 && n <= 29){ if(n%2 == 0) printf("%d", 1); else{ n-=9; printf("%d", n/2 - 1); } } else if(n > 29){
n-=29;
if(n%3 == 1) printf("%d", 1);
else if(n%3 == 2) printf("%d", (n - 2 + 3)/3 - 1)
}
*/
return 0;
}
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
https://www.prolightsfxjh.com/
Thank you!
------from ProLightsfx
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
如经许可后转载,请注明出处:https://prolightsfxjh.com/article/codeforces-round-352-div-2-a-summer-camp/
共有 0 条评论