Adding python files

This commit is contained in:
Arkagedon
2022-03-13 19:40:00 +01:00
parent 96c71d1d71
commit 70f29fa19e
22 changed files with 320 additions and 32 deletions

View File

@ -1,11 +1,8 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() int main()
{ {
//Getting the data
int L; int L;
scanf("%d", &L); scanf("%d", &L);
int H; int H;
@ -21,13 +18,14 @@ int main()
} }
int size=0; int size=0;
//On compte la taille du mot
//Counting the size of the word
for (int i =0; i < 257; i++) for (int i =0; i < 257; i++)
{ {
if (T[i] != '\0') if (T[i] != '\0')
{ {
size++; size++;
//On convertit notre mot //Convert the word
if (T[i] > 96 && T[i] < 123) if (T[i] > 96 && T[i] < 123)
T[i] -= 32; T[i] -= 32;
} }
@ -35,10 +33,10 @@ int main()
break; break;
} }
//Affichage du mot //Printing the word
for (int i = 0; i < H; i++) //On répète ça le nombre de lignes for (int i = 0; i < H; i++) //Repeat number of line times
{ {
for (int j = 0; j< size; j++) //Répétition du nombre de lettre pour afficher la ligne i de chaque lettre for (int j = 0; j< size; j++) //Repeat number of letter times
{ {
int id = T[j] - 65; int id = T[j] - 65;
//fprintf(stderr,"T = %d Id= %d\n",T[j],id); //fprintf(stderr,"T = %d Id= %d\n",T[j],id);
@ -59,8 +57,6 @@ int main()
} }
printf("\n"); printf("\n");
} }
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
return 0; return 0;
} }

Binary file not shown.

View File

@ -0,0 +1,25 @@
#include <stdlib.h>
#include <stdio.h>
int compare (const void *arg1, const void *arg2) {
return (*(int*)arg1 - *(int*)arg2);
}
int main()
{
int N, diff = 2147483647;
scanf("%d", &N);
int tab[N];
for (int i = 0; i < N; i++)
scanf("%d", &tab[i]);
qsort (tab,N,sizeof(int),compare);
for (int i =0; i<N; i++)
{
if (abs(tab[i] - tab[i+1]) < diff)
diff = abs(tab[i] - tab[i+1]);
}
printf("%d\n",diff);
return 0;
}

View File

@ -1,8 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
int main() int main()
{ {
// the number of points used to draw the surface of Mars. // the number of points used to draw the surface of Mars.

View File

@ -0,0 +1,23 @@
int main()
{
// game loop
while (1) {
char enemy1[257]; // name of enemy 1
scanf("%s", enemy1);
int dist1; // distance to enemy 1
scanf("%d", &dist1);
char enemy2[257]; // name of enemy 2
scanf("%s", enemy2);
int dist2; // distance to enemy 2
scanf("%d", &dist2);
if (dist1 < dist2) {
printf("%s\n", enemy1);
} else {
printf("%s\n", enemy2);
}
}
return 0;
}

View File

@ -1,7 +1,4 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() int main()
{ {
@ -17,8 +14,7 @@ int main()
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty); scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
// game loop // game loop
while (1) while (1) {
{
// The remaining amount of turns Thor can move. Do not remove this line. // The remaining amount of turns Thor can move. Do not remove this line.
int remaining_turns; int remaining_turns;
scanf("%d", &remaining_turns); scanf("%d", &remaining_turns);
@ -29,19 +25,37 @@ int main()
if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18)) if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18))
{ {
if (initial_tx > light_x) if (initial_tx > light_x)
dirX = "W", initial_tx--; {
dirX = "W";
initial_tx--;
}
else if (initial_tx < light_x) else if (initial_tx < light_x)
dirX = "E", initial_tx++; {
dirX = "E";
initial_tx++;
}
else else
{
dirX = ""; dirX = "";
}
if (initial_ty > light_y) if (initial_ty > light_y)
dirY = "N", initial_ty--; {
dirY = "N";
initial_ty--;
}
else if (initial_ty < light_y) else if (initial_ty < light_y)
dirY = "S", initial_ty++; {
dirY = "S";
initial_ty++;
}
else else
{
dirY = ""; dirY = "";
}
} }
printf("%s%s\n", dirY, dirX); printf("%s%s\n", dirY, dirX);
} }

View File

@ -1,6 +1,4 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Convert char into binary ascii //Convert char into binary ascii
void charToBin(char c, char *buffer) void charToBin(char c, char *buffer)

View File

@ -1,7 +1,5 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() int main()
{ {

View File

@ -1,7 +1,4 @@
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() int main()
{ {

View File

@ -0,0 +1,25 @@
import sys
import math
def distance (latA, lonA, latB, lonB):
x = (float(lonB) - float(lonA)) * math.cos((float(latA) + float(latB)) / 2)
y = (float(latB) - float(latA))
return math.sqrt(x**2 + y**2) * 6371
lon = input()
lon = float(lon.replace(",", "."))
lat = input()
lat = float(lat.replace(",", "."))
n = int(input())
defib = [input() for i in range(n)]
minDist = float('inf')
minName = ""
for i in range(n):
entry = defib[i].split(';')
dist = distance(lat, lon, float(entry[5].replace(",", ".")), float(entry[4].replace(",", ".")))
if (dist < minDist):
minDist = dist
minName = entry[1]
print(minName)

View File

@ -0,0 +1,12 @@
import sys
import math
n = int(input())
pi = [int(input()) for i in range(n)]
pi.sort()
min = float('inf')
for i in range(1,n):
if (pi[i] - pi[i-1] < min):
min = pi[i] - pi[i-1]
print(min)

View File

@ -0,0 +1,30 @@
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
surface_n = int(input()) # the number of points used to draw the surface of Mars.
for i in range(surface_n):
# land_x: X coordinate of a surface point. (0 to 6999)
# land_y: Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
land_x, land_y = [int(j) for j in input().split()]
# game loop
while True:
# h_speed: the horizontal speed (in m/s), can be negative.
# v_speed: the vertical speed (in m/s), can be negative.
# fuel: the quantity of remaining fuel in liters.
# rotate: the rotation angle in degrees (-90 to 90).
# power: the thrust power (0 to 4).
x, y, h_speed, v_speed, fuel, rotate, power = [int(i) for i in input().split()]
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
if (y > 1500):
power = 3
if (y < 1500 and v_speed < -35):
power = 4
# 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4).
print("0 " + str (power))

View File

@ -0,0 +1,22 @@
import sys
import math
n = int(input()) # Number of elements which make up the association table.
q = int(input()) # Number Q of file names to be analyzed.
d = {}
for i in range(n):
# ext: file extension
# mt: MIME type.
ext, mt = input().split()
d[ext.lower()] = mt
for i in range(q):
fname = input().lower().split(".") # One file name per line.
#print(stderr,fname)
if (len(fname) == 2 and fname[1] in d):
print(d[fname[1]])
elif (len(fname) > 2 and fname[len(fname)-1] in d):
print(d[fname[len(fname)-1]])
else:
print("UNKNOWN")

View File

@ -0,0 +1,11 @@
# game loop
while 1:
enemy_1 = input() # name of enemy 1
dist_1 = int(input()) # distance to enemy 1
enemy_2 = input() # name of enemy 2
dist_2 = int(input()) # distance to enemy 2
if (dist_1 < dist_2):
print(enemy_1)
else:
print(enemy_2)

View File

@ -0,0 +1,27 @@
# light_x: the X position of the light of power
# light_y: the Y position of the light of power
# initial_tx: Thor's starting X position
# initial_ty: Thor's starting Y position
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
# game loop
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
result = ""
if (initial_ty > light_y):
result += "N"
initial_ty -= 1
elif (initial_ty < light_y):
result += "S"
initial_ty += 1
if (initial_tx > light_x):
result += "W"
initial_tx += 1
elif (initial_tx < light_x):
result += "E"
initial_tx -= 1
# A single line providing the move to be made: N NE E SE S SW W or NW
print(result)

View File

@ -0,0 +1,19 @@
import sys
import math
n = int(input()) # the number of temperatures to analyse
min = float('inf')
for i in input().split():
# t: a temperature expressed as an integer ranging from -273 to 5526
t = int(i)
if (abs(0-t) < abs(0-min)):
min = t
elif min == t:
min = t
elif abs(min) == abs(t):
min = abs(min)
if (min == float('inf')):
print(0)
else:
print(min)

View File

@ -0,0 +1,7 @@
import sys
import math
# game loop
while True:
mountain_h = [int(input()) for i in range(8)] # represents the height of one mountain.
print(mountain_h.index(max(mountain_h)))

View File

@ -0,0 +1,45 @@
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
# nb_floors: number of floors
# width: width of the area
# nb_rounds: maximum number of rounds
# exit_floor: floor on which the exit is found
# exit_pos: position of the exit on its floor
# nb_total_clones: number of generated clones
# nb_additional_elevators: ignore (always zero)
# nb_elevators: number of elevators
nb_floors, width, nb_rounds, exit_floor, exit_pos, nb_total_clones, nb_additional_elevators, nb_elevators = [int(i) for i in input().split()]
print(exit_floor, exit_pos, file=sys.stderr, flush=True)
d = {}
for i in range(nb_elevators):
# elevator_floor: floor on which this elevator is found
# elevator_pos: position of the elevator on its floor
elevator_floor, elevator_pos = [int(j) for j in input().split()]
d[elevator_floor] = elevator_pos
print(d, file=sys.stderr, flush=True)
round = 0
# game loop
while True:
round += 1
inputs = input().split()
clone_floor = int(inputs[0]) # floor of the leading clone
clone_pos = int(inputs[1]) # position of the leading clone on its floor
direction = inputs[2] # direction of the leading clone: LEFT or RIGHT
print(clone_pos, clone_floor, direction, file=sys.stderr, flush=True)
if (clone_floor == exit_floor):
if ((exit_pos < clone_pos and direction == "RIGHT") or (exit_pos > clone_pos and direction == "LEFT")):
print("BLOCK")
else:
print("WAIT")
else:
if ((d.get(clone_floor, clone_pos+1) < clone_pos and direction == "RIGHT") or (d.get(clone_floor,clone_pos-1) > clone_pos and direction == "LEFT")):
print("BLOCK")
else:
print("WAIT")
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True

View File

@ -0,0 +1,10 @@
n = int(input())
max = 0
max_lost = 0
for i in input().split():
curr_lost = int(i) - max
if (curr_lost < max_lost):
max_lost = curr_lost
if (int(i) > max):
max = int(i)
print(max_lost)

View File

@ -0,0 +1,32 @@
import sys
import math
val = {'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'10':10,'J':11,'Q':12,'K':13,'A':14}
n = int(input()) # the number of cards for player 1
cardp_1 = [val[input()[:-1]] for i in range(n)]
m = int(input()) # the number of cards for player 2
cardp_2 = [val[input()[:-1]] for i in range(m)]
round = 0
def smallest_deck(): return min(len(cardp_1), len(cardp_2))
while ( smallest_deck() > 0):
round+=1
print(cardp_1, cardp_2, file=sys.stderr, flush=True)
compare = 0
while (cardp_1[compare] == cardp_2[compare]):
compare += 4
if compare > smallest_deck(): print("PAT"); break
if cardp_1[compare] > cardp_2[compare]:
cardp_1 = cardp_1[compare+1:] + cardp_1[:compare+1] + cardp_2[:compare+1]
cardp_2 = cardp_2[compare+1:]
else:
cardp_2 = cardp_2[compare+1:] + cardp_1[:compare+1] + cardp_2[:compare+1]
cardp_1 = cardp_1[compare+1:]
winner = 1 if len(cardp_2) == 0 else 2
print(winner, round)

View File

@ -16,7 +16,7 @@ __Be careful, a lot of my solutions aren't optimized because I didn't took time
|Unary | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/unary.c) | | |Unary | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/unary.c) | |
|Power of Thor - Chapter 1| [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/power_of_thor_1.c) | | |Power of Thor - Chapter 1| [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/power_of_thor_1.c) | |
|Onboarding | [x]() | | |Onboarding | [x]() | |
|Mars Lander - Chapter 1 | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/mars_landers_1.c) | | |Mars Lander - Chapter 1 | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/mars_lander_1.c) | |
|Horse racing duals | [x]() | | |Horse racing duals | [x]() | |
|Defibrillators | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/defibrillators.c) | | |Defibrillators | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/defibrillators.c) | |
|The descent | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/the_descent.c) | | |The descent | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/the_descent.c) | |

BIN
codingameLogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB