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 } 
  • 相关阅读:
    从客户端(Content="<p>666</p>")中检测到有潜在危险的 Request.Form 值。
    VS插件集
    Carmack在QUAKE3中使用的计算平方根的函数
    自动匹配HTTP请求中对应实体参数名的数据(性能不是最优)
    webapi单元测试时出现的ConfigurationManager.ConnectionStrings为空错误
    @@IDENTITY在加触发器时返回错误的ID值
    Protobuf完整实例
    Apache配置多个监听端口和不同的网站目录的简单方法[转]
    ThinkPHP 小技巧
    复选框 ajax取得后台页面
  • 原文地址:https://www.cnblogs.com/hsd-/p/5487149.html
Copyright © 2011-2022 走看看