zoukankan      html  css  js  c++  java
  • codeforces 672A A. Summer Camp(水题)

    题目链接:

    A. Summer Camp

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
     
    input
    3
    output
    3
    input
    11
    output
    0
    Note

    In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.

    In the second sample, the digit at position 11 is '0', it belongs to the integer 10.

    题意:

    问自然数组成的字符串的第n位的数是多少;

    思路:

    n<=1000,所以直接暴力跑一波;

    AC代码:

    #include <bits/stdc++.h>
    /*#include <iostream>
    #include <queue>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    */
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=2e4+5;
    
    int n;
    int main()
    {
    
        scanf("%d",&n);
        int cnt=0;
        for(int i=1;i<=1000;i++)
        {
            int temp=i,ans=0,num=0;
            while(temp)
            {
                ans=ans*10+temp%10;
                temp/=10;
                num++;
            }
            int s;
            while(num--)
            {
                s=ans%10;
                ans/=10;
                cnt++;
                if(cnt>=n)
                {
                    cout<<s<<"
    ";
                    return 0;
                }
    
            }
        }
    
        return 0;
    }
  • 相关阅读:
    Android Studio的project中两个build.gradle配置的区别
    build script和all projects作用和区别
    让overflow:auto页面滚动条出现时不跳动
    GreenDao设置数据版本
    Greendao 缓存问题
    js中文编码到C#后台解码
    content-type: application/json没有设置导致的500错误
    Android的Device File Explorer刷新文件
    adb server version (31) doesn't match this client (40); killing...
    Sqlserver远程过程调用失败
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5484494.html
Copyright © 2011-2022 走看看