Skip to content

Commit ebc4fb2

Browse files
committed
🚀 19-Nov-2020
1 parent 408f6d1 commit ebc4fb2

13 files changed

+861
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
3+
4+
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.
5+
6+
Input
7+
The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.
8+
9+
Output
10+
In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).
11+
12+
Examples
13+
inputCopy
14+
47
15+
outputCopy
16+
YES
17+
inputCopy
18+
16
19+
outputCopy
20+
YES
21+
inputCopy
22+
78
23+
outputCopy
24+
NO
25+
Note
26+
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
27+
28+
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
29+
*/
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
#include<bits/stdc++.h>
41+
using namespace std;
42+
43+
44+
bool isLucky(int tmp){
45+
while(tmp){
46+
if(!(tmp%10==4 || tmp%10==7)){
47+
return false;
48+
}
49+
tmp/=10;
50+
}
51+
return true;
52+
}
53+
54+
int main()
55+
{
56+
ios_base::sync_with_stdio(false);
57+
cin.tie(NULL);
58+
59+
int n;
60+
cin>>n;
61+
62+
bool lucky=true;
63+
64+
lucky=isLucky(n);
65+
66+
67+
if(lucky) cout<<"YES";
68+
else {
69+
for(int i=1;i<n;i++){
70+
if(n%i==0 && isLucky(i)){
71+
lucky=true;
72+
break;
73+
}
74+
}
75+
if(lucky) cout<<"YES";
76+
else cout<<"NO";
77+
}
78+
79+
return 0;
80+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
wHAT DO WE NEED cAPS LOCK FOR?
3+
4+
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
5+
6+
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
7+
8+
either it only contains uppercase letters;
9+
or all letters except for the first one are uppercase.
10+
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
11+
12+
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
13+
14+
Input
15+
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
16+
17+
Output
18+
Print the result of the given word's processing.
19+
20+
Examples
21+
inputCopy
22+
cAPS
23+
outputCopy
24+
Caps
25+
inputCopy
26+
Lock
27+
outputCopy
28+
Lock
29+
30+
*/
31+
32+
33+
34+
35+
36+
37+
#include<bits/stdc++.h>
38+
using namespace std;
39+
40+
int main()
41+
{
42+
ios_base::sync_with_stdio(false);
43+
cin.tie(NULL);
44+
45+
string s;
46+
cin>>s;
47+
48+
int cnt=0;
49+
50+
int n=s.length();
51+
52+
for(auto &ch: s){
53+
if(ch>='A' && ch<='Z') cnt++;
54+
}
55+
56+
if(cnt==n){
57+
for(int i=0;i<n;i++) s[i]=tolower(s[i]);
58+
} else if(s[0]>='a' && s[0]<='z' && cnt==n-1){
59+
s[0]=toupper(s[0]);
60+
for(int i=1;i<n;i++) s[i]=tolower(s[i]);
61+
}
62+
63+
cout<<s;
64+
65+
return 0;
66+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
HQ9+ is a joke programming language which has only four one-character instructions:
3+
4+
"H" prints "Hello, World!",
5+
"Q" prints the source code of the program itself,
6+
"9" prints the lyrics of "99 Bottles of Beer" song,
7+
"+" increments the value stored in the internal accumulator.
8+
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
9+
10+
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
11+
12+
Input
13+
The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.
14+
15+
Output
16+
Output "YES", if executing the program will produce any output, and "NO" otherwise.
17+
18+
Examples
19+
inputCopy
20+
Hi!
21+
outputCopy
22+
YES
23+
inputCopy
24+
Codeforces
25+
outputCopy
26+
NO
27+
Note
28+
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
29+
30+
In the second case none of the program characters are language instructions.
31+
32+
33+
*/
34+
35+
36+
37+
38+
39+
40+
41+
#include<bits/stdc++.h>
42+
using namespace std;
43+
44+
int main()
45+
{
46+
ios_base::sync_with_stdio(false);
47+
cin.tie(NULL);
48+
49+
string s;
50+
cin>>s;
51+
52+
bool print=false;
53+
54+
for(auto &ch: s){
55+
if(ch=='H' || ch=='Q' || ch=='9'){
56+
print=true;
57+
break;
58+
}
59+
}
60+
61+
if(print) cout<<"YES";
62+
else cout<<"NO";
63+
64+
return 0;
65+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
There is an infinite 2-dimensional grid. The robot stands in cell (0,0) and wants to reach cell (x,y). Here is a list of possible commands the robot can execute:
3+
4+
move north from cell (i,j) to (i,j+1);
5+
move east from cell (i,j) to (i+1,j);
6+
move south from cell (i,j) to (i,j−1);
7+
move west from cell (i,j) to (i−1,j);
8+
stay in cell (i,j).
9+
The robot wants to reach cell (x,y) in as few commands as possible. However, he can't execute the same command two or more times in a row.
10+
11+
What is the minimum number of commands required to reach (x,y) from (0,0)?
12+
13+
Input
14+
The first line contains a single integer t (1≤t≤100) — the number of testcases.
15+
16+
Each of the next t lines contains two integers x and y (0≤x,y≤104) — the destination coordinates of the robot.
17+
18+
Output
19+
For each testcase print a single integer — the minimum number of commands required for the robot to reach (x,y) from (0,0) if no command is allowed to be executed two or more times in a row.
20+
21+
Example
22+
inputCopy
23+
5
24+
5 5
25+
3 4
26+
7 1
27+
0 0
28+
2 0
29+
outputCopy
30+
10
31+
7
32+
13
33+
0
34+
3
35+
Note
36+
The explanations for the example test:
37+
38+
We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.
39+
40+
In the first test case, the robot can use the following sequence: NENENENENE.
41+
42+
In the second test case, the robot can use the following sequence: NENENEN.
43+
44+
In the third test case, the robot can use the following sequence: ESENENE0ENESE.
45+
46+
In the fourth test case, the robot doesn't need to go anywhere at all.
47+
48+
In the fifth test case, the robot can use the following sequence: E0E.
49+
50+
51+
*/
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
#include<bits/stdc++.h>
65+
using namespace std;
66+
67+
int main(){
68+
ios_base::sync_with_stdio(false);
69+
cin.tie(NULL);
70+
71+
int t;
72+
cin>>t;
73+
while(t--){
74+
int x, y;
75+
cin>>x>>y;
76+
77+
if(x==y) cout<<x+y<<"\n";
78+
else {
79+
int a=0, b=0;
80+
char dir, prev;
81+
if(x>y){
82+
dir='E';
83+
prev='O';
84+
} else {
85+
dir='N';
86+
prev='O';
87+
}
88+
int step=0;
89+
90+
while(a<x || b<y){
91+
if(dir=='E' && a<x && (prev=='N' || prev=='O')){
92+
a++;
93+
dir='N';
94+
prev='E';
95+
step++;
96+
}
97+
else if(dir=='N' && b<y && (prev=='E' || prev=='O')){
98+
b++;
99+
dir='E';
100+
prev='N';
101+
step++;
102+
} else if(b==y && dir=='N' ){
103+
step++;
104+
prev='O';
105+
dir='E';
106+
} else if(a==x && dir=='E'){
107+
step++;
108+
dir='N';
109+
prev='O';
110+
}
111+
112+
}
113+
114+
cout<<step<<"\n";
115+
}
116+
117+
118+
}
119+
120+
121+
return 0;
122+
}
123+
124+
125+
126+

0 commit comments

Comments
 (0)