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

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

1049. Counting Ones

2019-11-08 02:17:55
字體:
供稿:網(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:
12Sample Output:

5

#include <cstdio>#include <cstdlib>#include <iostream>#include <deque>#include <queue>#include <cstring>#include <vector>#include <string>#include <iomanip>#include <map>#include <set>#include <cmath>#include <stack>#include <cmath>#include <algorithm>using namespace std;#define max1 1000000int main() {    string n;    cin>>n;    int sum=0;    for(int i=0;i<n.size();i++){int mid=n[i]-'0';int left=atoi(n.substr(0,i).c_str());int right=atoi(n.substr(i+1,n.size()).c_str());int ex=n.size()-1-i;if(mid==0)sum+=left*pow(10,ex);else if(mid==1)sum+=pow(10,ex)*left+1+right;else sum+=pow(10,ex)*(left+1);}cout<<sum<<endl;    return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 定日县| 卓尼县| 当阳市| 南乐县| 孟州市| 内江市| 成武县| 遂宁市| 乌拉特前旗| 兖州市| 潞西市| 阜康市| 罗甸县| 云梦县| 怀宁县| 东光县| 沙田区| 龙州县| 绥芬河市| 孙吴县| 利辛县| 平泉县| 海门市| 桓台县| 洪湖市| 潼关县| 沁水县| 扬中市| 浠水县| 讷河市| 义乌市| 泸溪县| 平顺县| 都匀市| 乌拉特后旗| 靖边县| 班戈县| 石林| 锡林浩特市| 东乡县| 郸城县|