Skip to content

Commit a4ffe47

Browse files
committed
🚀 07-Jan-2021
1 parent 85ed78b commit a4ffe47

13 files changed

+985
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
3+
4+
Input
5+
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
6+
7+
Output
8+
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
9+
10+
Examples
11+
inputCopy
12+
aaaa
13+
aaaA
14+
outputCopy
15+
0
16+
inputCopy
17+
abs
18+
Abz
19+
outputCopy
20+
-1
21+
inputCopy
22+
abcdefg
23+
AbCdEfF
24+
outputCopy
25+
1
26+
Note
27+
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
28+
29+
http://en.wikipedia.org/wiki/Lexicographical_order
30+
*/
31+
32+
33+
34+
#include<bits/stdc++.h>
35+
using namespace std;
36+
37+
38+
int main(){
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(NULL);
41+
42+
string a, b;
43+
cin >> a >> b;
44+
45+
int n = a.length();
46+
47+
bool asmall = false, bsmall = false;
48+
49+
for (int i = 0; i < n; i++) {
50+
if (tolower(a[i]) < tolower(b[i])) {
51+
asmall = true;
52+
break;
53+
} else if (tolower(a[i]) > tolower(b[i])) {
54+
bsmall = true;
55+
break;
56+
}
57+
}
58+
59+
if (!asmall && !bsmall) cout << 0;
60+
else if (asmall) cout << -1;
61+
else cout << 1;
62+
63+
64+
return 0;
65+
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, …, 2k-1x candies during the k-th day. But there is an issue: Vova remembers neither x nor k but he is sure that x and k are positive integers and k>1.
3+
4+
Vova will be satisfied if you tell him any positive integer x so there is an integer k>1 that x+2x+4x+?+2k-1x=n. It is guaranteed that at least one solution exists. Note that k>1.
5+
6+
You have to answer t independent test cases.
7+
8+
Input
9+
The first line of the input contains one integer t (1=t=104) — the number of test cases. Then t test cases follow.
10+
11+
The only line of the test case contains one integer n (3=n=109) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer x and integer k>1 that x+2x+4x+?+2k-1x=n.
12+
13+
Output
14+
Print one integer — any positive integer value of x so there is an integer k>1 that x+2x+4x+?+2k-1x=n.
15+
16+
Example
17+
inputCopy
18+
7
19+
3
20+
6
21+
7
22+
21
23+
28
24+
999999999
25+
999999984
26+
outputCopy
27+
1
28+
2
29+
1
30+
7
31+
4
32+
333333333
33+
333333328
34+
Note
35+
In the first test case of the example, one of the possible answers is x=1,k=2. Then 1·1+2·1 equals n=3.
36+
37+
In the second test case of the example, one of the possible answers is x=2,k=2. Then 1·2+2·2 equals n=6.
38+
39+
In the third test case of the example, one of the possible answers is x=1,k=3. Then 1·1+2·1+4·1 equals n=7.
40+
41+
In the fourth test case of the example, one of the possible answers is x=7,k=2. Then 1·7+2·7 equals n=21.
42+
43+
In the fifth test case of the example, one of the possible answers is x=4,k=3. Then 1·4+2·4+4·4 equals n=28
44+
*/
45+
46+
47+
48+
49+
#include<bits/stdc++.h>
50+
using namespace std;
51+
52+
int main(){
53+
ios_base::sync_with_stdio(false);
54+
cin.tie(NULL);
55+
56+
int t;
57+
cin >> t;
58+
while (t--) {
59+
long long n;
60+
cin >> n;
61+
62+
int k = 2;
63+
64+
while (1) {
65+
int val = pow(2, k) - 1;
66+
if(n % val != 0) k++;
67+
else break;
68+
}
69+
70+
cout << n / (long long)(pow(2, k) - 1) << endl;
71+
}
72+
73+
return 0;
74+
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.
3+
4+
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.
5+
6+
Now Petya wants to know for each friend i the number of a friend who has given him a gift.
7+
8+
Input
9+
The first line contains one integer n (1?=?n?=?100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
10+
11+
Output
12+
Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.
13+
14+
Examples
15+
inputCopy
16+
4
17+
2 3 4 1
18+
outputCopy
19+
4 1 2 3
20+
inputCopy
21+
3
22+
1 3 2
23+
outputCopy
24+
1 3 2
25+
inputCopy
26+
2
27+
1 2
28+
outputCopy
29+
1 2
30+
31+
*/
32+
33+
34+
#include<bits/stdc++.h>
35+
using namespace std;
36+
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 + 1), res(n + 1);
46+
47+
for (int i = 1; i <= n; i++) cin >> v[i];
48+
49+
for (int i = 1; i <= n; i++) {
50+
res[v[i]] = i;
51+
}
52+
53+
for (int i = 1; i <=n; i++) cout << res[i] << " ";
54+
55+
return 0;
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
3+
4+
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
5+
6+
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
7+
8+
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
9+
10+
Input
11+
The first input line contains the only integer n (2?=?n?=?100) which represents the number of soldiers in the line. The second line contains integers a1,?a2,?...,?an (1?=?ai?=?100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers a1,?a2,?...,?an are not necessarily different.
12+
13+
Output
14+
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
15+
16+
Examples
17+
inputCopy
18+
4
19+
33 44 11 22
20+
outputCopy
21+
2
22+
inputCopy
23+
7
24+
10 10 58 31 63 40 76
25+
outputCopy
26+
10
27+
Note
28+
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
29+
30+
In the second sample the colonel may swap the soldiers in the following sequence:
31+
32+
(10, 10, 58, 31, 63, 40, 76)
33+
(10, 58, 10, 31, 63, 40, 76)
34+
(10, 58, 10, 31, 63, 76, 40)
35+
(10, 58, 10, 31, 76, 63, 40)
36+
(10, 58, 31, 10, 76, 63, 40)
37+
(10, 58, 31, 76, 10, 63, 40)
38+
(10, 58, 31, 76, 63, 10, 40)
39+
(10, 58, 76, 31, 63, 10, 40)
40+
(10, 76, 58, 31, 63, 10, 40)
41+
(76, 10, 58, 31, 63, 10, 40)
42+
(76, 10, 58, 31, 63, 40, 10)
43+
*/
44+
45+
46+
47+
48+
#include<bits/stdc++.h>
49+
using namespace std;
50+
51+
52+
int main(){
53+
ios_base::sync_with_stdio(false);
54+
cin.tie(NULL);
55+
56+
int n;
57+
cin >> n;
58+
59+
vector <int> v(n);
60+
61+
for (int i = 0; i < n; i++) cin >> v[i];
62+
63+
int mini = INT_MAX, maxi = INT_MIN, res = 0, miniInd = 0, maxiInd = 0;
64+
65+
for (int i = 0; i < n; i++) {
66+
if(v[i] <= mini) {
67+
mini = v[i];
68+
miniInd = i;
69+
}
70+
71+
}
72+
73+
for (int i = n - 1; i >= 0; i--) {
74+
if(v[i] >= maxi) {
75+
maxi = v[i];
76+
maxiInd = i;
77+
}
78+
}
79+
80+
res = (maxiInd - 0) + (n - 1)- miniInd;
81+
82+
if (maxiInd > miniInd) res -= 1;
83+
84+
85+
86+
cout << res;
87+
88+
return 0;
89+
}
90+
91+
92+
93+
94+
95+
96+
97+
98+
/*
99+
#include<bits/stdc++.h>
100+
using namespace std;
101+
102+
103+
int main(){
104+
ios_base::sync_with_stdio(false);
105+
cin.tie(NULL);
106+
107+
int n;
108+
cin >> n;
109+
110+
vector <int> v(n);
111+
112+
for (int i = 0; i < n; i++) cin >> v[i];
113+
114+
int mini = INT_MAX, maxi = INT_MIN, res = 0, miniInd = 0, maxiInd = 0;
115+
116+
for (int i = 0; i < n; i++) {
117+
if(v[i] <= mini) {
118+
mini = v[i];
119+
miniInd = i;
120+
}
121+
122+
}
123+
124+
for (int i = miniInd; i < n - 1; i++) {
125+
swap(v[i], v[i + 1]);
126+
res++;
127+
}
128+
129+
for (int i = n - 1; i >= 0; i--) {
130+
if(v[i] >= maxi) {
131+
maxi = v[i];
132+
maxiInd = i;
133+
}
134+
}
135+
136+
for (int i = maxiInd; i > 0; i--) {
137+
swap(v[i], v[i - 1]);
138+
res++;
139+
}
140+
141+
142+
cout << res;
143+
144+
return 0;
145+
}
146+
147+
*/
148+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int sod(int n){
5+
int sd = 0;
6+
while(n){
7+
sd += n % 10;
8+
n /= 10;
9+
}
10+
return sd;
11+
}
12+
13+
bool isUnique(int n){
14+
set <int> s;
15+
int digits = 0;
16+
while(n){
17+
s.insert(n % 10);
18+
n /= 10;
19+
digits++;
20+
}
21+
return s.size() == digits;
22+
}
23+
24+
int main(){
25+
ios_base::sync_with_stdio(false);
26+
cin.tie(NULL);
27+
28+
int t;
29+
cin >> t;
30+
while(t--){
31+
int x;
32+
cin >> x;
33+
int xsod = sod(x);
34+
35+
int i = 1;
36+
bool flag = false;
37+
while(i < INT_MAX){
38+
if(isUnique(i) && sod(i) == x){
39+
flag = true;
40+
break;
41+
}
42+
i++;
43+
}
44+
45+
if(!flag) cout << -1 << endl;
46+
else cout << i << endl;
47+
}
48+
49+
return 0;
50+
}
51+

0 commit comments

Comments
 (0)