Codeforces Round #352 (Div. 2) A. Summer Camp 水题

A. Summer Camp

题目连接:

http://www.codeforces.com/contest/672/problem/A

Description

Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.

This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is “123456789101112131415…”. Your task is to print the n-th digit of this string (digits are numbered starting with 1.

Input

The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

Output

Print the n-th digit of the line.

Sample Input

3

Sample Output

3

题意

这个串是1234567891011121314,这样一直下去的

现在给你n,让你输出第n个字符是啥

题解:

数据范围才1000,直接暴力模拟就好了……

代码

#include<bits/stdc++.h>
using namespace std;
string s,s1;
int add=1;
int main()
{
    while(s.size()<1000)
    {
        s1="";
        int tmp=add;
        while(tmp)
        {
            s1+=(tmp%10+'0');
            tmp/=10;
        }
        reverse(s1.begin(),s1.end());
        s+=s1;
        add++;
    }
    int n;scanf("%d",&n);
    cout<<s[n-1]<<endl;
}
    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/5486232.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞