Skip to content

Commit c36a5fe

Browse files
committed
🚀 27-Mar-2021
1 parent 36ff38f commit c36a5fe

8 files changed

+520
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test cases.
3+
4+
Input
5+
The first line of the input contains one integer t (1=t=104) — the number of test cases. Then t test cases follow.
6+
7+
The only line of the test case contains two integers a and b (1=a,b=109).
8+
9+
Output
10+
For each test case print the answer — the minimum number of moves you need to do in order to make a divisible by b.
11+
12+
Example
13+
inputCopy
14+
5
15+
10 4
16+
13 9
17+
100 13
18+
123 456
19+
92 46
20+
outputCopy
21+
2
22+
5
23+
4
24+
333
25+
0
26+
*/
27+
28+
29+
30+
31+
#include<bits/stdc++.h>
32+
using namespace std;
33+
34+
int main(){
35+
ios_base::sync_with_stdio(false);
36+
cin.tie(NULL);
37+
38+
int t;
39+
cin >> t;
40+
41+
while (t--) {
42+
int a, b;
43+
cin >> a >> b;
44+
45+
int r = a % b;
46+
47+
int res = r ? b - r : r;
48+
49+
cout << res << endl;
50+
51+
}
52+
53+
54+
return 0;
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that:
3+
4+
Alice will get a (a>0) candies;
5+
Betty will get b (b>0) candies;
6+
each sister will get some integer number of candies;
7+
Alice will get a greater amount of candies than Betty (i.e. a>b);
8+
all the candies will be given to one of two sisters (i.e. a+b=n).
9+
Your task is to calculate the number of ways to distribute exactly n candies between sisters in a way described above. Candies are indistinguishable.
10+
11+
Formally, find the number of ways to represent n as the sum of n=a+b, where a and b are positive integers and a>b.
12+
13+
You have to answer t independent test cases.
14+
15+
Input
16+
The first line of the input contains one integer t (1=t=104) — the number of test cases. Then t test cases follow.
17+
18+
The only line of a test case contains one integer n (1=n=2·109) — the number of candies you have.
19+
20+
Output
21+
For each test case, print the answer — the number of ways to distribute exactly n candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 0.
22+
23+
Example
24+
inputCopy
25+
6
26+
7
27+
1
28+
2
29+
3
30+
2000000000
31+
763243547
32+
outputCopy
33+
3
34+
0
35+
0
36+
1
37+
999999999
38+
381621773
39+
Note
40+
For the test case of the example, the 3 possible ways to distribute candies are:
41+
42+
a=6, b=1;
43+
a=5, b=2;
44+
a=4, b=3.
45+
*/
46+
47+
48+
49+
50+
51+
#include<bits/stdc++.h>
52+
using namespace std;
53+
54+
int main(){
55+
ios_base::sync_with_stdio(false);
56+
cin.tie(NULL);
57+
58+
int t;
59+
cin >> t;
60+
61+
while (t--) {
62+
int n;
63+
cin >> n;
64+
65+
if (n % 2)
66+
cout << n / 2 << endl;
67+
else cout << n / 2 - 1 << endl;
68+
}
69+
70+
71+
72+
return 0;
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
3+
4+
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
5+
6+
You are given a positive integer n (1=n=104). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
7+
8+
Input
9+
The first line contains an integer t (1=t=104) — the number of test cases in the input. Then t test cases follow.
10+
11+
Each test case is a line containing an integer n (1=n=104).
12+
13+
Output
14+
Print t answers to the test cases. Each answer must begin with an integer k — the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
15+
16+
Example
17+
inputCopy
18+
5
19+
5009
20+
7
21+
9876
22+
10000
23+
10
24+
outputCopy
25+
2
26+
5000 9
27+
1
28+
7
29+
4
30+
800 70 6 9000
31+
1
32+
10000
33+
1
34+
10
35+
*/
36+
37+
38+
39+
40+
#include<bits/stdc++.h>
41+
using namespace std;
42+
43+
int main(){
44+
ios_base::sync_with_stdio(false);
45+
cin.tie(NULL);
46+
47+
int t;
48+
cin >> t;
49+
50+
while (t--) {
51+
int n;
52+
cin >> n;
53+
54+
vector <int> res;
55+
56+
while (n) {
57+
int digits = log10(n) + 1;
58+
int m = pow(10, digits - 1);
59+
res.push_back(n - n % m);
60+
n = n % m;
61+
}
62+
63+
cout << res.size() << endl;
64+
for (auto &x: res) cout << x << " ";
65+
cout << endl;
66+
}
67+
68+
return 0;
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
3+
4+
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
5+
6+
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
7+
8+
Input
9+
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
10+
11+
Output
12+
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
13+
14+
Examples
15+
inputCopy
16+
SANTACLAUS
17+
DEDMOROZ
18+
SANTAMOROZDEDCLAUS
19+
outputCopy
20+
YES
21+
inputCopy
22+
PAPAINOEL
23+
JOULUPUKKI
24+
JOULNAPAOILELUPUKKI
25+
outputCopy
26+
NO
27+
inputCopy
28+
BABBONATALE
29+
FATHERCHRISTMAS
30+
BABCHRISTMASBONATALLEFATHER
31+
outputCopy
32+
NO
33+
Note
34+
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
35+
36+
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
37+
38+
In the third sample there's an extra letter "L".
39+
*/
40+
41+
42+
43+
44+
#include<bits/stdc++.h>
45+
using namespace std;
46+
47+
int main(){
48+
ios_base::sync_with_stdio(false);
49+
cin.tie(NULL);
50+
51+
string g, h, s;
52+
cin >> g >> h >> s;
53+
54+
int freq[26] = {0};
55+
56+
for (auto &x: g) freq[x - 'A']++;
57+
for(auto &x: h) freq[x - 'A']++;
58+
59+
for (auto &x: s) freq[x - 'A']--;
60+
61+
bool flag = true;
62+
63+
for (auto &x: freq) {
64+
if (x != 0) {
65+
flag = false;
66+
break;
67+
}
68+
}
69+
70+
if (flag) cout << "YES";
71+
else cout << "NO";
72+
73+
74+
return 0;
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
3+
4+
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
5+
6+
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
7+
8+
Input
9+
The first line contains the single integer n (1?=?n?=?1000) — the number of contests where the coder participated.
10+
11+
The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
12+
13+
Output
14+
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
15+
16+
Examples
17+
inputCopy
18+
5
19+
100 50 200 150 200
20+
outputCopy
21+
2
22+
inputCopy
23+
10
24+
4664 6496 5814 7010 5762 5736 6944 4850 3698 7242
25+
outputCopy
26+
4
27+
Note
28+
In the first sample the performances number 2 and 3 are amazing.
29+
30+
In the second sample the performances number 2, 4, 9 and 10 are amazing.
31+
*/
32+
33+
34+
35+
#include<bits/stdc++.h>
36+
using namespace std;
37+
38+
int main(){
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(NULL);
41+
42+
int n;
43+
cin >> n;
44+
45+
vector <int> v(n);
46+
47+
for (int i = 0; i < n; i++) cin >> v[i];
48+
49+
int best = v[0], worst = v[0];
50+
51+
int res = 0;
52+
53+
for (int i = 1; i < n; i++) {
54+
if (v[i] > best) {
55+
best = v[i];
56+
res++;
57+
} else if(v[i] < worst){
58+
worst = v[i];
59+
res++;
60+
}
61+
}
62+
63+
cout << res;
64+
65+
66+
return 0;
67+
}
68+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
3+
4+
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
5+
6+
Input
7+
The first line contains four space-separated integers s1,?s2,?s3,?s4 (1?=?s1,?s2,?s3,?s4?=?109) — the colors of horseshoes Valera has.
8+
9+
Consider all possible colors indexed with integers.
10+
11+
Output
12+
Print a single integer — the minimum number of horseshoes Valera needs to buy.
13+
14+
Examples
15+
inputCopy
16+
1 7 3 3
17+
outputCopy
18+
1
19+
inputCopy
20+
7 7 7 7
21+
outputCopy
22+
3
23+
24+
*/
25+
26+
27+
28+
29+
#include<bits/stdc++.h>
30+
using namespace std;
31+
32+
int main(){
33+
ios_base::sync_with_stdio(false);
34+
cin.tie(NULL);
35+
36+
int s1, s2, s3, s4;
37+
cin >> s1 >> s2 >> s3 >> s4;
38+
39+
set <int> s;
40+
41+
s.insert(s1);
42+
s.insert(s2);
43+
s.insert(s3);
44+
s.insert(s4);
45+
46+
cout << 4 - s.size();
47+
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)