国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1049. Counting Ones (30)

2019-11-11 03:54:42
字體:
來源:轉載
供稿:網友

The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12.

Input Specification:

Each input file contains one test case which gives the positive N (<=230).

Output Specification:

For each test case, PRint the number of 1’s in one line.

Sample Input: 12 Sample Output: 5 題意:找出0~N內的個數,共有多少個1 算法:對每一位單獨考慮,看該位可能存在多少個1; 可以找一個數,找出規律,如:30701,對個,十,百,千,萬各位分析;

#include<cstdio>int main(){ int n,a=1,ans=0; int left,right,now; scanf("%d",&n); while(n/a){ left=n/(a*10); now=n/a%10; right=n%a; if(now<1) ans+=left*a; else if(now==1) ans+=left*a+right+1; else if(now>1) ans+=(left+1)*a; a*=10; } printf("%d/n",ans); return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云南省| 韩城市| 旺苍县| 中方县| 莱西市| 东阳市| 鲁甸县| 肇庆市| 邳州市| 通山县| 县级市| 武宁县| 监利县| 天全县| 余干县| 郓城县| 平原县| 龙江县| 沧源| 双流县| 弥勒县| 天台县| 周口市| 博野县| 潢川县| 北碚区| 濮阳市| 日照市| 中山市| 墨玉县| 双城市| 武平县| 富蕴县| 黄大仙区| 图片| 东方市| 剑阁县| 会宁县| 丰宁| SHOW| 永年县|