zoukankan      html  css  js  c++  java
  • Codeforces Round #352 (Div. 2) A

    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.

    题意:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...". 连续的数 组成一个字符串(无空格 ,只是便于理解) 请输出n位置上的字符

    题解: 可以直接暴力!!! 比赛的时候想多了  分析出  1~99 共189位 最多为一个三位数 分段分析 注意细节

     1 #include<bits/stdc++.h>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<map>
     6 #include<queue>
     7 #include<stack>
     8 #define ll __int64
     9 #define pi acos(-1.0)
    10 using namespace std;
    11 int n;
    12 int main()
    13 {
    14     scanf("%d",&n);
    15     if(n<=9)
    16     {
    17     cout<<n<<endl;
    18     return  0;
    19     }
    20     if(n>9&&n<=189)
    21     {
    22         n=n-8;
    23         int exm=n/2;
    24          n--; 
    25          n=n%2; 
    26         if(n==0)
    27         cout<<(exm+9)%10<<endl;
    28         else
    29         cout<<(exm+9)/10<<endl;
    30         return 0;
    31     }
    32     if(n>189)
    33     {
    34         n=n-187;
    35         int exm=n/3;
    36         n=n-2;
    37         n=n%3;
    38         if(n==0)
    39         cout<<(exm+99)%10<<endl;
    40         if(n==1)
    41         cout<<(exm+99)/100<<endl;
    42         if(n==2)
    43         cout<<(exm+99-(exm+99)/100*100)/10<<endl;
    44         return 0;    
    45     }
    46     return 0;
    47 } 
  • 相关阅读:
    C#画K线图代码
    SQL查询效率:100w数据查询只需要1秒钟
    全程图解 手把手教你做RAID磁盘阵列
    炒股高手实战技巧
    数据库主键设计之思考
    如何做磁盘阵列和磁盘镜象
    股海心法—浓缩股市精华
    如何做磁盘阵列
    SQL Server 2005实现负载均衡的详细介绍!
    K线六种形态
  • 原文地址:https://www.cnblogs.com/hsd-/p/5487149.html
Copyright © 2011-2022 走看看