mirror of
https://github.com/Oxbian/CodingGame.git
synced 2025-07-07 04:14:27 +02:00
Adding python files
This commit is contained in:
@ -1,11 +1,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
//Getting the data
|
||||
int L;
|
||||
scanf("%d", &L);
|
||||
int H;
|
||||
@ -21,13 +18,14 @@ int main()
|
||||
}
|
||||
|
||||
int size=0;
|
||||
//On compte la taille du mot
|
||||
|
||||
//Counting the size of the word
|
||||
for (int i =0; i < 257; i++)
|
||||
{
|
||||
if (T[i] != '\0')
|
||||
{
|
||||
size++;
|
||||
//On convertit notre mot
|
||||
//Convert the word
|
||||
if (T[i] > 96 && T[i] < 123)
|
||||
T[i] -= 32;
|
||||
}
|
||||
@ -35,10 +33,10 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
//Affichage du mot
|
||||
for (int i = 0; i < H; i++) //On répète ça le nombre de lignes
|
||||
//Printing the word
|
||||
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;
|
||||
//fprintf(stderr,"T = %d Id= %d\n",T[j],id);
|
||||
@ -59,8 +57,6 @@ int main()
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
|
||||
// To debug: fprintf(stderr, "Debug messages...\n");
|
||||
|
||||
return 0;
|
||||
}
|
Binary file not shown.
25
C/Easy_Challenges/horse-racing-duals.c
Normal file
25
C/Easy_Challenges/horse-racing-duals.c
Normal 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;
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
// the number of points used to draw the surface of Mars.
|
23
C/Easy_Challenges/onboarding.c
Normal file
23
C/Easy_Challenges/onboarding.c
Normal 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;
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -17,8 +14,7 @@ int main()
|
||||
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
|
||||
|
||||
// game loop
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
// The remaining amount of turns Thor can move. Do not remove this line.
|
||||
int 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 > light_x)
|
||||
dirX = "W", initial_tx--;
|
||||
{
|
||||
dirX = "W";
|
||||
initial_tx--;
|
||||
}
|
||||
else if (initial_tx < light_x)
|
||||
dirX = "E", initial_tx++;
|
||||
{
|
||||
dirX = "E";
|
||||
initial_tx++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dirX = "";
|
||||
}
|
||||
|
||||
if (initial_ty > light_y)
|
||||
dirY = "N", initial_ty--;
|
||||
{
|
||||
dirY = "N";
|
||||
initial_ty--;
|
||||
}
|
||||
else if (initial_ty < light_y)
|
||||
dirY = "S", initial_ty++;
|
||||
{
|
||||
dirY = "S";
|
||||
initial_ty++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dirY = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("%s%s\n", dirY, dirX);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//Convert char into binary ascii
|
||||
void charToBin(char c, char *buffer)
|
@ -1,7 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
25
Python/Easy_Challenges/defibrillators.py
Normal file
25
Python/Easy_Challenges/defibrillators.py
Normal 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)
|
12
Python/Easy_Challenges/horse_racing_duals.py
Normal file
12
Python/Easy_Challenges/horse_racing_duals.py
Normal 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)
|
30
Python/Easy_Challenges/mars_lander_1.py
Normal file
30
Python/Easy_Challenges/mars_lander_1.py
Normal 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))
|
22
Python/Easy_Challenges/mime-type.py
Normal file
22
Python/Easy_Challenges/mime-type.py
Normal 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")
|
||||
|
11
Python/Easy_Challenges/onboarding.py
Normal file
11
Python/Easy_Challenges/onboarding.py
Normal 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)
|
27
Python/Easy_Challenges/power_of_thor_1.py
Normal file
27
Python/Easy_Challenges/power_of_thor_1.py
Normal 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)
|
19
Python/Easy_Challenges/temperatures.py
Normal file
19
Python/Easy_Challenges/temperatures.py
Normal 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)
|
7
Python/Easy_Challenges/the_descent.py
Normal file
7
Python/Easy_Challenges/the_descent.py
Normal 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)))
|
45
Python/Medium_Challenges/don't_panic_1.py
Normal file
45
Python/Medium_Challenges/don't_panic_1.py
Normal 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
|
10
Python/Medium_Challenges/stock_exchange_losses.py
Normal file
10
Python/Medium_Challenges/stock_exchange_losses.py
Normal 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)
|
32
Python/Medium_Challenges/winamax_battle.py
Normal file
32
Python/Medium_Challenges/winamax_battle.py
Normal 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)
|
@ -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) | |
|
||||
|Power of Thor - Chapter 1| [x](https://github.com/ARKAGEDON/CodingGame/blob/main/C/Easy_Challenges/power_of_thor_1.c) | |
|
||||
|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]() | |
|
||||
|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) | |
|
||||
|
BIN
codingameLogo.png
Normal file
BIN
codingameLogo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user