国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 秭归县| 平谷区| 徐闻县| 常州市| 日土县| 长岛县| 洛川县| 洪泽县| 犍为县| 灵川县| 泰安市| 长沙市| 百色市| 博兴县| 高平市| 泽州县| 红河县| 康定县| 鄂尔多斯市| 哈巴河县| 泾阳县| 黔江区| 留坝县| 兰考县| 九龙县| 福鼎市| 珠海市| 探索| 长汀县| 昌乐县| 淮北市| 高要市| 湖南省| 濮阳县| 大方县| 应用必备| 得荣县| 海城市| 大姚县| 铁岭县| 上林县|