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

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

PAT A1049. Counting Ones (30)

2019-11-08 02:01:31
字體:
來源:轉載
供稿:網友

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:
12Sample Output:
5
#include <cstdio>#include <algorithm>#include <cstring>#include <string>#define Max 100010using namespace std;int main(){	int n,k=1;	int m=0;	int p,q,r,l;	scanf("%d",&n);	for(int i=1;i<=n;i++)	{		p=i;		while(p!=0)		{			q=p%10;			if(q==1) m++;			p=p/10;		}	}		printf("%d/n",m);	system("pause");	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安图县| 晋州市| 平罗县| 裕民县| 宁城县| 任丘市| 偏关县| 禹城市| 江都市| 石渠县| 蒲江县| 隆化县| 鸡东县| 长葛市| 台山市| 临颍县| 新竹县| 泉州市| 新源县| 渝北区| 西藏| 郯城县| 滨州市| 乐清市| 陕西省| 金坛市| 色达县| 九龙城区| 商丘市| 陕西省| 滨海县| 西乌| 集贤县| 昌邑市| 资讯 | 乡宁县| 兴和县| 长垣县| 凤翔县| 红桥区| 柞水县|