pat advanced level 1049

1049 Counting Ones (30)(30 分)

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 (<=2^30^).

Output Specification:

For each test case, print the number of 1‘s in one line.

Sample Input:

12

Sample Output:

5

原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/9223968.html

时间: 2024-07-30 15:31:36

pat advanced level 1049的相关文章

PAT (Advanced Level) 1049 Counting Ones

题解 now - 当前位的数值 left - 在now左边的所有数字 right - 在now右边的所有数字 mul - right的数量级,如 10,100,100 ① 如果 now == 0 ,当now可以为1时,左边的数值必须为(0 ~ (left-1)),右边的数值可以是 0 ~ 999… ,所以情况有 left*mul ② 如果 now == 1 ,在第①种情况下,再加上right+1,因为当前位已经为1,所以右边的数right在当前范围下是什么无所谓,所以情况为 left*mul+r

Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

Pat1043代码 题目描述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes

Pat(Advanced Level)Practice--1044(Shopping in Mars)

Pat1044代码 题目描述: Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam

PAT (Advanced Level) 1093. Count PAT&#39;s (25)

预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstring> long long MOD=1e9+7; const int maxn=1e5+10; long long dp1[maxn],dp2[maxn]; char s[maxn]; int main() { scanf("%s",s); memset(dp1,0,sizeof d

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

Pat(Advanced Level)Practice--1018(Public Bike Management)

Pat1018代码 题目描述: There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bike Management C

Pat(Advanced Level)Practice--1076(Forwards on Weibo)

Pat1076代码 题目描述: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all hi

Pat(Advanced Level)Practice--1016(Phone Bills)

Pat1016代码 题目描述: A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a lon

1093. Count PAT&#39;s (25)【计数】——PAT (Advanced Level) Practise

题目信息 1093. Count PAT's (25) 时间限制120 ms 内存限制65536 kB 代码长度限制16000 B The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th c