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

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

1049. Counting Ones (30)

2019-11-11 04:22:57
字體:
來源:轉載
供稿:網友

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;}
上一篇:git 初篇

下一篇:Kruskal算法的C語言程序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杨浦区| 虹口区| 化德县| 晋江市| 屯门区| 奉节县| 潜山县| 台北市| 游戏| 上杭县| 城口县| 临清市| 阳高县| 安达市| 微博| 义乌市| 锡林郭勒盟| 调兵山市| 左贡县| 浮梁县| 沙洋县| 塔城市| 安福县| 内乡县| 云林县| 建昌县| 五大连池市| 罗源县| 烟台市| 金门县| 融水| 高邮市| 定襄县| 和田市| 中卫市| 昆山市| 红河县| 达日县| 霍城县| 平乐县| 巴彦县|