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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1049. Counting Ones (30)

2019-11-11 05:03:14
字體:
供稿:網(wǎng)友

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內(nèi)的個(gè)數(shù),共有多少個(gè)1 算法:對(duì)每一位單獨(dú)考慮,看該位可能存在多少個(gè)1; 可以找一個(gè)數(shù),找出規(guī)律,如:30701,對(duì)個(gè),十,百,千,萬各位分析;

#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;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 九龙城区| 叶城县| 南昌市| 泾川县| 梓潼县| 牡丹江市| 礼泉县| 新余市| 潞西市| 土默特左旗| 桐城市| 绩溪县| 迁安市| 连云港市| 杭州市| 桓台县| 新巴尔虎左旗| 铜梁县| 海丰县| 乡宁县| 天全县| 行唐县| 云浮市| 偏关县| 涟源市| 且末县| 陕西省| 临漳县| 乌鲁木齐市| 隆安县| 洛阳市| 万盛区| 乡城县| 延津县| 海兴县| 疏附县| 乌海市| 吉安县| 文安县| 河池市| 黎平县|