Codeforces Round #352 (Div. 2) A.Summer Camp
来源:互联网 发布:数据黑产吧 编辑:程序博客网 时间:2024/05/22 15:11
A. Summer Camp
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputEvery 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
题意:1234567891011....这样的一串序列,问你第几数字是多少?
思路:分个位,十位,百位进行讨论,个位时直接输出,十位数时,n小于190,ans=n-10,然后讨论ans如果是偶数则是十位的数,ans除以20再加1就是结果。如果ans是奇数,与20取模,除以2就是结果。百位数时,也是同样进行讨论即可。
#include <stdio.h>#include <iostream>using namespace std;int main(){ int n; while(~scanf("%d",&n)) { if(n<=9) { printf("%d\n",n); continue; } if(n<=189) { int a=n-10; int b=a/20; int c=a%20; if(c%2==0) { printf("%d\n",b+1); continue; } if(c%2==1) { printf("%d\n",c/2); continue; } } if(n<=1000) { int a=n-190; int d=a/300; a=a-(d)*300; if(a%3==0) { printf("%d\n",d+1); continue; } int b=a/30; int c=a%30; if(a%3==1) { printf("%d\n",b); continue; } if(a%3==2) { printf("%d\n",c/3); continue; } } }}
总结:利用分类讨论的思想。
0 0
- Codeforces Round #352 (Div. 2) A.Summer Camp
- Codeforces Round #352 (Div. 2)-Summer Camp(模拟)
- Codeforces Round #352 (Div. 2) A. Summer Camp __ water problem
- CodeForces 672A Summer Camp
- CodeForces-672A-Summer Camp
- CodeForces 672A Summer Camp
- [CodeForces]-672A-Summer Camp
- codeforces 672A Summer Camp
- CodeForces 672A Summer Camp 【sprintf】
- A. Summer Camp
- CodeForces - 672A Summer Camp (模拟)水
- CodeForces 672A Summer Camp(数字游戏,枚举)
- Codeforces Round #352 (Div. 2) (A-E)
- Codeforces Round #415 (Div. 2) B. Summer sell-off
- Codeforces Round #415 (Div. 2) B. Summer sell-off
- Tutorial CodeForces Round 289 (Div.2) (Second Winter Computer Camp Selection 2015) 题解
- 【Codeforces Round #194 (Div. 1)】Codeforces 333E Summer Earnings
- Codeforces Round #352 (Div. 2) A B C
- torch学习
- Android Studio 混淆代码
- Apache服务器最新版下载、安装及配置(win版
- Android调用系统分享直接抵达微信
- 杂的文
- Codeforces Round #352 (Div. 2) A.Summer Camp
- 安装win7、windows server 2012 出现无法配置在此计算机硬件上运行 解决方案
- 初学java反射机制
- 使用logstash+elasticsearch+kibana快速搭建日志平台
- 1.2.21 Map.values方法——获取Map集合中的所有键值对象
- SpringMVC开发笔记
- 2016/5/27 1004. 简单减法
- Qt之自定义布局管理器(QCardLayout)
- 通过命令的方式实现计算机定时关机