https://codeforces.com/contest/1702https://codeforces.com/contest/1702
A. Round Down the Price
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
At the store, the salespeople want to make all prices round.
In this problem, a number that is a power of 1010 is called a round number. For example, the numbers 100=1100=1, 101=10101=10, 102=100102=100 are round numbers, but 2020, 110110 and 256256 are not round numbers.
So, if an item is worth mm bourles (the value of the item is not greater than 109109), the sellers want to change its value to the nearest round number that is not greater than mm. They ask you: by how many bourles should you decrease the value of the item to make it worth exactly 10k10k bourles, where the value of kk — is the maximum possible (kk — any non-negative integer).
For example, let the item have a value of 178178-bourles. Then the new price of the item will be 100100, and the answer will be 178−100=78178−100=78.
Input
The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases .
Each test case is a string containing a single integer mm (1≤m≤1091≤m≤109) — the price of the item.
Output
For each test case, output on a separate line a single integer dd (0≤d
Example
input
Copy
7
1
2
178
20
999999999
9000
987654321
output
Copy
0
1
78
10
899999999
8000
887654321
Note
In the example:
- 1−0=1001−0=100,
- 2−1=1002−1=100,
- 178−78=102178−78=102,
- 20−10=10120−10=101,
- 999999999−899999999=108999999999−899999999=108,
- 9000−8000=1039000−8000=103,
- 987654321−887654321=108987654321−887654321=108.
Note that in each test case, we get the maximum possible round number.
这道题目要求降价,具体降价要求就是需要取一个最接近价格并且不大于价格的10的次方数。要注意最后输出用printf,count会科学计数。
#include
#include
#include
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int prize,x=1,flag=0;
cin>>prize;
while(prize>=x)
{
x=x*10;
flag++;
}
prize-=pow(10,flag-1);
printf("%dn",prize);
}
}
B. Polycarp Writes a String from Memory
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp has a poor memory. Each day he can remember no more than 33 of different letters.
Polycarp wants to write a non-empty string of ss consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it?
Polycarp initially has an empty string and can only add characters to the end of that string.
For example, if Polycarp wants to write the string lollipops, he will do it in 22 days:
- on the first day Polycarp will memorize the letters l, o, i and write lolli;
- On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops.
If Polycarp wants to write the string stringology, he will do it in 44 days:
- in the first day will be written part str;
- on day two will be written part ing;
- on the third day, part of olog will be written;
- on the fourth day, part of y will be written.
For a given string ss, print the minimum number of days it will take Polycarp to write it.
Input
The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.
Each test case consists of a non-empty string ss consisting of lowercase Latin letters (the length of the string ss does not exceed 2⋅1052⋅105) — the string Polycarp wants to construct.
It is guaranteed that the sum of string lengths ss over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, print a single number — minimum number of days it will take Polycarp to write the string ss from memory.
Example
input
Copy
6
lollipops
stringology
abracadabra
codeforces
test
f
output
Copy
2
4
3
4
1
1
这题需要用到容器中的map,key值存字符,value存字符出现次数,因为一次最多只能出现三个不同的字符,所以如果容器中等于三个字符时,判断新进来的字符容器中是否已经存在,存在的话,加入即可。不存在的话,清空容器,重新开始第二轮,并且计数器+1 。要注意的是,最后可能会有剩余的字符并且不足三个,不会被清空计数器也不会+1,所以在最后我们还需要对容器进行检查是否有剩余,有的话+1。
#include
#include
#include