Skip to content

Commit 6e8a6c2

Browse files
author
hir12111
committed
Add a few problems
1 parent a8b38ae commit 6e8a6c2

35 files changed

+906
-0
lines changed

beautifulmatrix.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
int one_i, one_j, num;
13+
for(int i=0;i<5;i++) {
14+
for(int j=0;j<5;j++) {
15+
cin >> num;
16+
if (num == 1) {
17+
one_i = i;
18+
one_j = j;
19+
}
20+
}
21+
}
22+
int result = abs(2-one_i) + abs(2-one_j);
23+
cout << result << endl;
24+
return 0;
25+
}

beautifulyear.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
bool is_beautiful(int year) {
10+
bool digits[10] = {false};
11+
while (year) {
12+
int d = year % 10;
13+
if (digits[d]) return false;
14+
digits[d] = true;
15+
year/=10;
16+
}
17+
return true;
18+
}
19+
20+
int main()
21+
{
22+
ios::sync_with_stdio(false);
23+
int year;
24+
cin >> year;
25+
year++;
26+
while(not is_beautiful(year)) year++;
27+
cout << year << endl;
28+
return 0;
29+
}

bitplusplus.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
int n;
13+
cin >> n;
14+
int x = 0;
15+
string input;
16+
for(int i=0;i<n;i++) {
17+
cin >> input;
18+
if (input.find("++") != string::npos) x++;
19+
else if (input.find("--") != string::npos) x--;
20+
}
21+
cout << x << endl;
22+
return 0;
23+
}

bobbob.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main(int argc, char **argv)
5+
{
6+
int tc;
7+
cin >> tc;
8+
while(tc--) {
9+
int n, a, b, c, d;
10+
cin >> n >> a >> b >> c >> d;
11+
if (a+b+c+d > n/2) cout << "Yes" << endl;
12+
else cout << "No" << endl;
13+
}
14+
return 0;
15+
}

boyorgirl.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
bool carset['z'-'a'+1];
10+
int main()
11+
{
12+
ios::sync_with_stdio(false);
13+
string input;
14+
cin >> input;
15+
for (char c : input)
16+
carset[c-'a'] = true;
17+
int res=0;
18+
for(int i=0;i<'z'-'a'+1;i++) {
19+
res += (int) carset[i];
20+
}
21+
if (res % 2)
22+
cout << "IGNORE HIM!" << endl;
23+
else
24+
cout << "CHAT WITH HER!" << endl;
25+
26+
return 0;
27+
}

capslock.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
bool is_error(string input) {
10+
assert(input.size() > 1);
11+
for(int i=1;i<(int)input.size();i++) {
12+
char c = input[i];
13+
if (not (c >= 'A' && c <= 'Z'))
14+
return false;
15+
}
16+
return true;
17+
}
18+
char toggle(char c) {
19+
if (c >= 'A' && c <= 'Z')
20+
return tolower(c);
21+
if (c >= 'a' && c <= 'z')
22+
return toupper(c);
23+
return c;
24+
}
25+
int main()
26+
{
27+
ios::sync_with_stdio(false);
28+
string input;
29+
cin >> input;
30+
if (input.size() == 1) {
31+
cout << (char) toggle(input[0]) << endl;
32+
return 0;
33+
}
34+
if (is_error(input)) {
35+
transform(input.begin()+1, input.end(), input.begin()+1,
36+
[](char c) -> char { return tolower(c); });
37+
input[0] = toggle(input[0]);
38+
}
39+
cout << input << endl;
40+
41+
return 0;
42+
}

chatroom.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
string input;
13+
string test = "hello";
14+
int i=0;
15+
cin >> input;
16+
for(char c : input) {
17+
if (test[i] == c) {
18+
i++;
19+
if (i>= test.size()) break;
20+
}
21+
}
22+
if (i>=test.size()) cout << "YES" << endl;
23+
else cout << "NO" << endl;
24+
return 0;
25+
}

dominopiling.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
int m, n;
13+
cin >> m >> n;
14+
if (m==1 && n==1) {
15+
cout << 0 << endl;
16+
return 0;
17+
}
18+
int res = m*n/2;
19+
cout << res << endl;
20+
return 0;
21+
}

football.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
string input;
13+
cin >> input;
14+
int first = 0;
15+
int second = 0;
16+
for(auto c : input) {
17+
if (c=='0') {
18+
first++;
19+
second = 0;
20+
} else {
21+
second++;
22+
first = 0;
23+
}
24+
if (first >= 7 || second >= 7) {
25+
cout << "YES" << endl;
26+
return 0;
27+
}
28+
}
29+
cout << "NO" << endl;
30+
31+
return 0;
32+
}

georgeandaccomodation.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
int n;
13+
cin >> n;
14+
int a, b;
15+
int res = 0;
16+
for(int i=0;i<n;i++) {
17+
cin >> a >> b;
18+
if (b-a >= 2) res++;
19+
}
20+
cout << res << endl;
21+
return 0;
22+
}

helpfulmath.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
string input;
13+
cin >> input;
14+
sort(input.begin(), input.end());
15+
for(int i=input.size()/2;i<input.size()-1;i++) {
16+
cout << input[i] << "+";
17+
}
18+
cout << input[input.size()-1] << endl;
19+
20+
21+
return 0;
22+
}

hqmplus.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
int main()
10+
{
11+
ios::sync_with_stdio(false);
12+
string input;
13+
cin >> input;
14+
for (char c : input) {
15+
if (c=='Q' || c=='H' || c=='9') {
16+
cout << "YES" << endl;
17+
return 0;
18+
}
19+
}
20+
cout << "NO" << endl;
21+
return 0;
22+
}

kefaandfirststeps.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
int arr[100001];
9+
int m[100001];
10+
int main()
11+
{
12+
ios::sync_with_stdio(false);
13+
int n;
14+
cin >> n;
15+
for(int i=0;i<n;i++) {
16+
cin >> arr[i];
17+
}
18+
int result=1;
19+
int count=1;
20+
for(int i=1;i<n;i++) {
21+
if(arr[i] >= arr[i-1]) count++;
22+
else count=1;
23+
result = max(result, count);
24+
}
25+
cout << result << endl;
26+
return 0;
27+
}

luckydivision.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef pair<int, int> ii;
5+
typedef tuple<int, int, int> iii;
6+
typedef vector<ii > vii;
7+
typedef vector<iii > viii;
8+
9+
bool is_lucky(int x) {
10+
while(x) {
11+
if (x%10 != 4 && x%10 != 7) return false;
12+
x /= 10;
13+
}
14+
return true;
15+
}
16+
int main()
17+
{
18+
ios::sync_with_stdio(false);
19+
int n;
20+
cin >> n;
21+
if (is_lucky(n)) {
22+
cout << "YES" << endl;
23+
return 0;
24+
}
25+
for(int i=4;i<=(n/2);i++) {
26+
if (n%i==0 && is_lucky(i)) {
27+
cout << "YES" << endl;
28+
return 0;
29+
}
30+
}
31+
cout << "NO" << endl;
32+
return 0;
33+
}

0 commit comments

Comments
 (0)