牛客网——字符串练习

链接:https://www.nowcoder.net/acm/contest/40/D
来源:牛客网

题目描述

珂朵莉想求123456789101112131415...的第n项

输入描述:

第一行一个整数n

输出描述:

第一行输出一个整数,表示答案
示例1

输入

3

输出

3
示例2

输入

11

输出

0

说明

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4...
第3个是3
第11个是0

备注:

对于100%的数据,有1 <= n <= 1000
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
typedef long long  ll;

const int inf = 0x3f3f3f3f;
const int moder = 1e9 + 7;
const int MAXN=1000010;

int main()
{
    string string1 = "";
    for(int i=1;i < 1000;i++)
    {
        char c[10];
        sprintf(c,"%d",i);
        string1 = string1 + c;
    }
    int n;
    while(cin >> n)
    {
        cout << string1[n-1] << endl;
    }
    return 0;
}

int 转换为char 用sprintf

原文地址:https://www.cnblogs.com/cunyusup/p/8412952.html