Skip to content

Commit afe295c

Browse files
committed
Initial commit
0 parents  commit afe295c

37 files changed

+905
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.o
2+
a.out

airport.c

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main(){
5+
int passengers, planes, * seats, max = 0, min = 0;
6+
int i, j, aux;
7+
8+
scanf("%d %d", &passengers, &planes);
9+
10+
seats = (int *) malloc(sizeof(int) * planes);
11+
12+
for(i = 0; i < planes; i++){
13+
scanf("%d", &seats[i]);
14+
}
15+
16+
for(i = 0; i < planes; i++){
17+
for(j = i + 1; j < planes; j++){
18+
if(seats[j] > seats[i]){
19+
aux = seats[i];
20+
seats[i] = seats[j];
21+
seats[j] = aux;
22+
}
23+
}
24+
}
25+
26+
int k = 0, tmp = seats[k];
27+
28+
for(i = 0; i < passengers; i++){
29+
min += (tmp --);
30+
31+
if(tmp == 0)
32+
tmp = seats[++ k];
33+
}
34+
35+
for(i = 0; i < passengers; i++){
36+
max += seats[0];
37+
38+
seats[0] -= 1;
39+
40+
for (k = 1; k < planes; k++){
41+
if (seats[k - 1] >= seats[k])
42+
break;
43+
44+
tmp = seats[k];
45+
seats[k] = seats[k - 1];
46+
seats[k-1] = tmp;
47+
}
48+
}
49+
50+
printf("%d %d\n", max, min);
51+
free(seats);
52+
return 0;
53+
}

amusing_joke.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(int argc, char const *argv[]) {
6+
string guest, host, pile;
7+
bool theres_host, theres_guest;
8+
int i, j, aux=0;
9+
10+
cin >> guest >> host >> pile;
11+
12+
13+
for(i=0;i<guest.size();i++)
14+
for(j=0;j<pile.size();j++)
15+
if(guest[i] == pile[j]){
16+
pile[j] = '#';
17+
aux++;
18+
break;
19+
}
20+
theres_guest = (aux == guest.size()) ? true : false;
21+
22+
aux=0;
23+
for(i=0;i<host.size();i++)
24+
for(j=0;j<pile.size();j++)
25+
if(host[i] == pile[j]){
26+
pile[j] = '#';
27+
aux++;
28+
break;
29+
}
30+
theres_host = (aux == host.size()) ? true : false;
31+
32+
33+
cout << ((pile.find_first_not_of('#') == -1 && theres_host && theres_guest) ? "YES" : "NO" ) << endl;
34+
35+
return 0;
36+
}

arrival_of_the_general.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main(int argc, char const *argv[]) {
5+
int line, bigger=-32768, biggerID, smaller=32767, smallerID, i, n, seconds;
6+
7+
scanf("%d", &n);
8+
9+
for(i=0; i < n;i++){
10+
scanf("%d", &line);
11+
12+
if(bigger < line){
13+
bigger = line;
14+
biggerID = i+1;
15+
}
16+
if(smaller >= line){
17+
smaller = line;
18+
smallerID = i+1;
19+
}
20+
}
21+
22+
seconds = (biggerID-1) + (n - smallerID);
23+
24+
if (biggerID > smallerID) //When this happens the swap between them are double counted
25+
seconds--;
26+
27+
printf("%d\n", seconds);
28+
29+
return 0;
30+
}

beatiful_matrix.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main (){
5+
int mtx, i, j, total = 0;
6+
int row, column;
7+
8+
for (i = 0; i < 5; i++){
9+
for (j = 0; j < 5; j++){
10+
scanf("%d", &mtx);
11+
if (mtx == 1){
12+
row = i;
13+
column = j;
14+
}
15+
}
16+
}
17+
18+
total = abs(2 - row) + abs(2 - column);
19+
20+
printf("%d\n", total);
21+
22+
return 0;
23+
}

beatiful_year.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
int num;
5+
int i;
6+
7+
scanf("%d", &num);
8+
9+
for(i= ++num; i <= 10000; i++){
10+
if ( (i%10 != i/10%10) && (i % 10 != i/100%10) && (i%10 != i/1000)
11+
&& (i/10%10 != i/100%10) && (i/10%10 != i/1000) && (i/100%10 != i/1000)){
12+
13+
printf("%d\n", i);
14+
break;
15+
}
16+
17+
}
18+
19+
return 0;
20+
}

bit++.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
char operation[4];
5+
int statements, X=0, i;
6+
7+
scanf("%d", &statements);
8+
9+
for(i=0;i<statements;i++){
10+
scanf("%s", operation);
11+
12+
if(operation[0] == '+' || operation[1] == '+' || operation[2] == '+')
13+
X++;
14+
else if(operation[0] == '-' || operation[1] == '-' || operation[2] == '-')
15+
X--;
16+
}
17+
18+
printf("%d\n", X);
19+
20+
return 0;
21+
}

borze.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
#define MAX 200
5+
6+
int main(int argc, char const *argv[]) {
7+
char code[MAX];
8+
int size, i;
9+
10+
scanf("%s", code);
11+
12+
size = strlen(code);
13+
14+
for(i = 0; i < size; i++){
15+
if (code[i] == '.')
16+
printf("0");
17+
else if (code[i+1] == '.'){
18+
printf("1");
19+
i++;
20+
}
21+
else{
22+
printf("2");
23+
i++;
24+
}
25+
}
26+
27+
printf("\n");
28+
29+
return 0;
30+
}

boy_or_girl.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(int argc, char const *argv[]) {
6+
string user_name;
7+
int i, j, distinct_characters;
8+
9+
cin >> user_name;
10+
distinct_characters = user_name.size();
11+
12+
for(i=0;i<user_name.size();i++)
13+
for(j=i+1;j<user_name.size();j++)
14+
if(user_name[i]==user_name[j]){
15+
distinct_characters--;
16+
user_name[j] = -j;
17+
}
18+
19+
cout << (((distinct_characters%2) == 0) ? "CHAT WITH HER!" : "IGNORE HIM!") << endl;
20+
21+
return 0;
22+
}

cupboards.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
3+
#define MIN(x,y) ((x < y) ? x : y)
4+
5+
int main(int argc, char const *argv[]) {
6+
int cupboards, left, right, i;
7+
int lf_closed=0, lf_opened=0, rt_closed=0, rt_opened=0, seconds=0;
8+
9+
scanf("%d", &cupboards);
10+
for (i = 0; i < cupboards; i++) {
11+
scanf("%d %d", &left, &right);
12+
13+
left ? lf_closed++ : lf_opened++;
14+
right ? rt_closed++ : rt_opened++;
15+
}
16+
seconds = MIN(lf_closed, lf_opened) + MIN(rt_closed, rt_opened);
17+
18+
printf("%d\n", seconds);
19+
20+
return 0;
21+
}

dima_and_friends.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
int friends, fingers=0, dima=0, aux, i;
5+
6+
scanf("%d", &friends);
7+
8+
for(i=0;i<friends;i++){
9+
scanf("%d", &aux);
10+
fingers += aux;
11+
}
12+
13+
for(i=1;i<=5;i++){
14+
aux = fingers + i;
15+
if (aux%(friends+1) != 1) //Including Dima
16+
dima++;
17+
}
18+
19+
printf("%d\n", dima);
20+
21+
return 0;
22+
}

drinks.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
int drinks, franctions, i;
5+
double total, volume = 0;
6+
7+
scanf("%d", &drinks);
8+
9+
for (i = 0; i < drinks; i++) {
10+
scanf("%d", &franctions);
11+
volume += franctions;
12+
}
13+
14+
total = volume / drinks;
15+
16+
printf("%.12lf\n", total);
17+
18+
return 0;
19+
}

effective_aproach.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(int argc, char const *argv[]) {
6+
long long n, m, Vasya=0, Petya=0, aux, i, j;
7+
long long a[100000], b[100000], c[100000];
8+
9+
cin >> n;
10+
11+
for(i=0;i<n;i++){
12+
cin >> a[i];
13+
c[a[i]] = i; //Keeping the position of the element on array c
14+
}
15+
16+
cin >> m;
17+
18+
for(i=0;i<m;i++){
19+
cin >> b[i];
20+
}
21+
22+
for(i=0;i<m;i++)
23+
Vasya += c[b[i]] + 1; //Accessing the position of element b
24+
25+
for(i=0;i<m;i++)
26+
Petya += n - c[b[i]]; //Accessing the position of element b
27+
28+
cout << Vasya << ' ' << Petya << endl;
29+
30+
return 0;
31+
}

helpful_maths.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(int argc, char const *argv[]) {
6+
string calculation;
7+
int i, j, base;
8+
9+
cin >> calculation;
10+
11+
for(i=2; i < calculation.size(); i+=2){
12+
base=calculation[i];
13+
14+
for(j=i; j && calculation[j-2] > base; j-=2)
15+
calculation[j] = calculation[j-2];
16+
17+
calculation[j]=base;
18+
}
19+
20+
cout << calculation << endl;
21+
22+
return 0;
23+
}

hq9+.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(int argc, char const *argv[]) {
6+
string program;
7+
8+
cin >> program;
9+
10+
if (program.find('H') != -1 || program.find('Q') != -1 || program.find('9') != -1)
11+
printf("YES\n");
12+
else
13+
printf("NO\n");
14+
15+
return 0;
16+
}

0 commit comments

Comments
 (0)