Added challenges of the first trial
This commit is contained in:
parent
49bd065a7f
commit
d7e5a09cb6
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
int value, pos;
|
||||
} Node;
|
||||
|
||||
void selectionSort(Node * sequence, int size) {
|
||||
int i, j, pos;
|
||||
Node aux;
|
||||
|
||||
for (i = 0; i < size - 1; i++) {
|
||||
pos = i;
|
||||
for (j = i + 1; j < size; j++)
|
||||
if (sequence[j].value < sequence[pos].value)
|
||||
pos = j;
|
||||
aux = sequence[i];
|
||||
sequence[i] = sequence[pos];
|
||||
sequence[pos] = aux;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n, i, size, value;
|
||||
Node * array;
|
||||
|
||||
scanf("%d\n%d", &n, &size);
|
||||
while (n > 0) {
|
||||
array = malloc(size * sizeof(*array));
|
||||
for (i = 0; i < size; i++) {
|
||||
array[i].pos = i;
|
||||
scanf("%d", &value);
|
||||
array[i].value = value;
|
||||
}
|
||||
selectionSort(array, size);
|
||||
for (i = 0; i < size; i++)
|
||||
printf("%d-%d ", array[i].value, array[i].pos);
|
||||
printf("\n");
|
||||
free(array);
|
||||
n--;
|
||||
}
|
||||
return 0;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(){
|
||||
int n;
|
||||
char c1, c2, output;
|
||||
|
||||
for(scanf("%d\n", &n); n > 0; n--) {
|
||||
while (scanf("%c", &c1) && c1 != '\n') {
|
||||
if (c1 == ' ') {
|
||||
printf(" ");
|
||||
continue;
|
||||
}
|
||||
scanf("%c", &c2);
|
||||
output = 'A' + 5 * (c1 - '0') + (c2 - '0');
|
||||
if (output <= 'Z'){
|
||||
printf("%c", output);
|
||||
continue;
|
||||
}
|
||||
switch (output) {
|
||||
case 'Z' + 1:
|
||||
printf(",");
|
||||
break;
|
||||
case 'Z' + 2:
|
||||
printf(".");
|
||||
break;
|
||||
case 'Z' + 3:
|
||||
printf("?");
|
||||
break;
|
||||
default:
|
||||
printf("!");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main () {
|
||||
int n = 0;
|
||||
char c;
|
||||
|
||||
for (scanf("%d\n", &n); n > 0; n--) {
|
||||
while (scanf("%c", &c) && c != '\n') {
|
||||
switch (c) {
|
||||
case 'D':
|
||||
printf("Rolada tatica ninja.\n");
|
||||
break;
|
||||
case 'E':
|
||||
printf("Esquerdei, e agora?\n");
|
||||
break;
|
||||
case 'C':
|
||||
printf("Eita pipoco. Zumm!\n");
|
||||
break;
|
||||
case 'B':
|
||||
printf("\n");
|
||||
break;
|
||||
case 'F':
|
||||
printf("Pronto e agora, e agora?\n");
|
||||
break;
|
||||
case 'A':
|
||||
printf("Nem ferrando. Vou de agentes mesmo.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,101 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int resolve (char game[3][3], int * line) {
|
||||
int i, j;
|
||||
char win = 'O';
|
||||
|
||||
for (i = 1; i < 3; i++) {
|
||||
|
||||
/* Teste horizontal */
|
||||
for (j = 0; j < 9; j++) {
|
||||
if (game[j / 3][j % 3] != win)
|
||||
j += 2 - (j % 3);
|
||||
else if (j % 3 == 2) {
|
||||
if (win == 'V') {
|
||||
j -= 2;
|
||||
do {
|
||||
line[j % 3] = 10 * (j / 3) + (j % 3) + 11;
|
||||
game[j / 3][j % 3] = 'X';
|
||||
j++;
|
||||
} while(j % 3 != 0);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Teste vertical */
|
||||
for (j = 0; j < 9; j++) {
|
||||
if (game[j % 3][j / 3] != win)
|
||||
j += 2 - (j % 3);
|
||||
else if (j % 3 == 2) {
|
||||
if (win == 'V') {
|
||||
j -= 2;
|
||||
do {
|
||||
line[j % 3] = 10 * (j % 3) + (j / 3) + 11;
|
||||
game[j % 3][j / 3] = 'X';
|
||||
j++;
|
||||
} while(j % 3 != 0);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Caso diagonal direto */
|
||||
for (j = 0; j < 3; j++) {
|
||||
if (game[j][j] != win)
|
||||
break;
|
||||
if (j == 2) {
|
||||
if (win == 'V') {
|
||||
for (j = 0; j < 3; j++) {
|
||||
line[j] = 11 * j + 11;
|
||||
game[j][j] = 'X';
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Caso diagonal inverso */
|
||||
for (j = 0; j < 3; j++) {
|
||||
if (game[2 - j][j] != win)
|
||||
break;
|
||||
if (j == 2) {
|
||||
if (win == 'V') {
|
||||
for (j = 0; j < 3; j++) {
|
||||
line[2 - j] = 10 * (2 - j) + j + 11;
|
||||
game[2 - j][j] = 'X';
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
win = 'V';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main () {
|
||||
int i, line[3], n = 0;
|
||||
char game[3][3];
|
||||
|
||||
for (scanf("%d", &n); n > 0; n--) {
|
||||
for (i = 0; i < 9; i++)
|
||||
scanf(" %c", &game[i / 3][i % 3]);
|
||||
switch (resolve(game, line)) {
|
||||
case 0:
|
||||
printf("Bora outra valendo os dois Tic-Tac ?\n");
|
||||
break;
|
||||
case 1:
|
||||
printf("Tic-Tac de cereja eh bom tambem\n");
|
||||
break;
|
||||
default:
|
||||
printf("Hora de tirar o bafo\n%d-%d-%d\n", line[0], line[1], line[2]);
|
||||
for (i = 0; i < 9; i++) {
|
||||
printf("%c ", game[i / 3][i % 3]);
|
||||
if (i % 3 == 2)
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue