NCPC26 ending
This commit is contained in:
34 files changed
+612
-311
No files matched your search
Generated
+77
@@ -0,0 +1,77 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int ship_x, ship_y;
|
||||
int treasure_x, treasure_y;
|
||||
int direction_x, direction_y;
|
||||
int movement_help;
|
||||
|
||||
scanf("%d %d", &ship_x, &ship_y);
|
||||
scanf("%d %d", &treasure_x, &treasure_y);
|
||||
|
||||
|
||||
|
||||
while (((ship_x == treasure_x) && (ship_y == treasure_y))==0){
|
||||
direction_x = ship_x - treasure_x;
|
||||
direction_y = ship_y - treasure_y;
|
||||
|
||||
//diagonal movement
|
||||
if (abs(direction_x) == abs(direction_y)){
|
||||
//NortEeast movment
|
||||
if((direction_x < 0) && (direction_y < 0)){
|
||||
printf("NE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//NortWest movement
|
||||
else if((direction_x > 0) && (direction_y < 0)){
|
||||
printf("NW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthWest movement
|
||||
else if((direction_x > 0) && (direction_y > 0)){
|
||||
printf("SW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthEast movement
|
||||
else if((direction_x < 0) && (direction_y > 0)){
|
||||
printf("SE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
}
|
||||
else if((abs(direction_x) != abs(direction_y))){
|
||||
//horisontal / vertical movement
|
||||
if(abs(direction_x) > abs(direction_y)){
|
||||
movement_help = abs(abs(direction_x) - abs(direction_y));
|
||||
//East movement
|
||||
if(direction_x < 0){
|
||||
printf("E\n");
|
||||
ship_x += movement_help;
|
||||
}
|
||||
//West movement
|
||||
if(direction_x > 0){
|
||||
printf("W\n");
|
||||
ship_x -= movement_help;
|
||||
}
|
||||
}
|
||||
if(abs(direction_x) < abs(direction_y)){
|
||||
movement_help = abs( abs(direction_y) - abs(direction_x));
|
||||
//North Movement
|
||||
if(direction_y < 0){
|
||||
printf("N\n");
|
||||
ship_y += movement_help;
|
||||
}
|
||||
//South Movement
|
||||
if(direction_y > 0){
|
||||
printf("S\n");
|
||||
ship_y -= movement_help;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
BIN
Binary file not shown.
Generated
Whitespace-only changes.
@@ -1,152 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int array[26];
|
||||
int time = 0;
|
||||
char problem;
|
||||
char RightOrWrong[10];
|
||||
int sum = 0;
|
||||
int solved = 0;
|
||||
int is_solved[26];
|
||||
|
||||
for (int i = 0 ; i < 26; i++){
|
||||
is_solved[i] = 0;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 26; i++)
|
||||
{
|
||||
array[i] = 0;
|
||||
}
|
||||
|
||||
while(scanf("%d %c %s", &time, &problem, &RightOrWrong) == 3 && time != -1){
|
||||
|
||||
|
||||
switch (problem){
|
||||
case 'A':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[0] += 20;
|
||||
}else{
|
||||
array[0] += time;
|
||||
solved += 1;
|
||||
is_solved[0] = 1;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[1] += 20;
|
||||
}else{
|
||||
array[1] += time;
|
||||
solved += 1;
|
||||
is_solved[1] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[2] += 20;
|
||||
}else{
|
||||
array[2] += time;
|
||||
solved += 1;
|
||||
is_solved[2] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[3] += 20;
|
||||
}else{
|
||||
array[3] += time;
|
||||
solved += 1;
|
||||
is_solved[3] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[4] += 20;
|
||||
}else{
|
||||
array[4] += time;
|
||||
solved += 1;
|
||||
is_solved[4] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[5] += 20;
|
||||
}else{
|
||||
array[5] += time;
|
||||
solved += 1;
|
||||
is_solved[5] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'G':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[6] += 20;
|
||||
}else{
|
||||
array[6] += time;
|
||||
solved += 1;
|
||||
is_solved[6] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[7] += 20;
|
||||
}else{
|
||||
array[7] += time;
|
||||
solved += 1;
|
||||
is_solved[7] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[8] += 20;
|
||||
}else{
|
||||
array[8] += time;
|
||||
solved += 1;
|
||||
is_solved[8] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'J':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[9] += 20;
|
||||
}else{
|
||||
array[9] += time;
|
||||
solved += 1;
|
||||
is_solved[9] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
if (strcmp(RightOrWrong, "wrong")==0){
|
||||
array[10] += 20;
|
||||
}else{
|
||||
array[10] += time;
|
||||
solved += 1;
|
||||
is_solved[10] = 1;
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
for(int i = 0; i <= 26; i++)
|
||||
{
|
||||
if(is_solved[i]==1){
|
||||
sum += array[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("%d %d", solved, sum);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user