Adding the first coding game Challenges

This commit is contained in:
Arkagedon
2022-01-27 11:31:40 +01:00
parent 2a876df769
commit e8bac6e221
10 changed files with 421 additions and 1 deletions

View File

@ -0,0 +1,66 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
int L;
scanf("%d", &L);
int H;
scanf("%d", &H); fgetc(stdin);
char tab[L][1025];
char T[257];
scanf("%[^\n]", T); fgetc(stdin);
for (int i = 0; i < H; i++) {
char ROW[1025];
scanf("%[^\n]", ROW); fgetc(stdin);
for (int j=0; j<1025; j++)
tab[i][j] = ROW[j];
}
int size=0;
//On compte la taille du mot
for (int i =0; i < 257; i++)
{
if (T[i] != '\0')
{
size++;
//On convertit notre mot
if (T[i] > 96 && T[i] < 123)
T[i] -= 32;
}
else
break;
}
//Affichage du mot
for (int i = 0; i < H; i++) //On répète ça le nombre de lignes
{
for (int j = 0; j< size; j++) //Répétition du nombre de lettre pour afficher la ligne i de chaque lettre
{
int id = T[j] - 65;
//fprintf(stderr,"T = %d Id= %d\n",T[j],id);
if ((id >= 0 && id < 26))
{
for (int k =(id*L); k<((id+1)*(L)); k++)
{
printf("%c",tab[i][k]);
}
}
else
{
for (int k =(26*L); k<(27*(L)); k++)
{
printf("%c",tab[i][k]);
}
}
}
printf("\n");
}
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
return 0;
}

View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Convert char into binary ascii
void charToBin(char c, char *buffer)
{
for (int i = 6; i >=0; i--)
{
buffer[i] = '0' + c%2;
c/=2;
}
buffer[7] = '\n';
}
int main()
{
char MESSAGE[101], binary[8], binMessage[707], prev;
int i = 0, j = 0, count = 0;
scanf("%[^\n]", MESSAGE);
binMessage[0] = '\0'; //Reset the string
for (int i = 0; i < strlen(MESSAGE); i++)
{
charToBin(MESSAGE[i], binary);
strncat(binMessage,binary,7); //Adding the binary of each char into the binMessage string
}
for (i =0; binMessage[i] != '\0'; i++)
{
if (binMessage[i] != prev)
{
for (j=0; j<count; j++)
printf("0");
if (count != 0)
printf(" ");
printf((binMessage[i] == '0') ? "00 " : "0 ");
count =1;
}
else
count++;
prev = binMessage[i];
}
for (int j = 0 ; j < count ; j++) //Showing the rest of the binMessage string
printf("0");
return 0;
}

View File

@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
// the number of points used to draw the surface of Mars.
int surface_n;
scanf("%d", &surface_n);
for (int i = 0; i < surface_n; i++) {
// X coordinate of a surface point. (0 to 6999)
int land_x;
// Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
int land_y;
scanf("%d%d", &land_x, &land_y);
}
// game loop
while (1) {
int X;
int Y;
// the horizontal speed (in m/s), can be negative.
int h_speed;
// the vertical speed (in m/s), can be negative.
int v_speed;
// the quantity of remaining fuel in liters.
int fuel;
// the rotation angle in degrees (-90 to 90).
int rotate;
// the thrust power (0 to 4).
int power;
scanf("%d%d%d%d%d%d%d", &X, &Y, &h_speed, &v_speed, &fuel, &rotate, &power);
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
int final_power = 0;
// 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).
if (Y > 1500)
final_power = 3;
if (Y < 1500 && v_speed < -35)
final_power = 4;
printf("0 %d\n",final_power);
}
return 0;
}

View File

@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
// the X position of the light of power
int light_x;
// the Y position of the light of power
int light_y;
// Thor's starting X position
int initial_tx;
// Thor's starting Y position
int initial_ty;
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
// game loop
while (1)
{
// The remaining amount of turns Thor can move. Do not remove this line.
int remaining_turns;
scanf("%d", &remaining_turns);
char *dirX = "";
char *dirY = "";
if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18))
{
if (initial_tx > light_x)
dirX = "W", initial_tx--;
else if (initial_tx < light_x)
dirX = "E", initial_tx++;
else
dirX = "";
if (initial_ty > light_y)
dirY = "N", initial_ty--;
else if (initial_ty < light_y)
dirY = "S", initial_ty++;
else
dirY = "";
}
printf("%s%s\n", dirY, dirX);
}
return 0;
}

View File

@ -0,0 +1,40 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define TAILLE_MAX 10000
int main()
{
// the number of temperatures to analyse
int n,min=TAILLE_MAX;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
// a temperature expressed as an integer ranging from -273 to 5526
int t;
scanf("%d", &t);
if (abs((0-t)) < abs(0-min))
{
min = t;
}
else if (min == t)
{
min = t;
}
else if (abs(t) == abs(min))
{
min = abs(min);
}
}
// Write an answer using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
if (min == TAILLE_MAX)
printf("0");
else
printf("%d",min);
return 0;
}

View File

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
// game loop
while (1) {
int mountain_max = 0, mountain_Id = 0;
for (int i = 0; i < 8; i++) {
// represents the height of one mountain.
int mountain_h;
scanf("%d", &mountain_h);
if (mountain_h > mountain_max)
{
mountain_max = mountain_h;
mountain_Id = i;
}
}
printf("%d\n",mountain_Id);
}
return 0;
}