#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int parse_input( char inp[200], char name[10] ){
int i =0;
for(; i < strlen(inp); i++ ){
if( inp[i] == ':' ){
break;
}
name[i] = inp[i];
}
name[i] = '\0';
i++;
int score = 0;
for(; i < strlen(inp); i++ ){
score*= 10;
score = score + (inp[i]-'0');
};
return score;
}
int isMatch( char a[], char b[] ){
if( strlen(a) == strlen(b) ){
int i =0 ;
for(; i < strlen(a); i++){
if( a[i] != b[i]
){ return 0;}
}
return 1;
}
return 0;
}
void cpyCharArray( char copyInto[], char copyWhat[] ){
int i = 0;
for(; i < strlen(copyWhat); i++){
copyInto[i] = copyWhat[i];
}
copyInto[i] = '\0';
return;
}
int cmpFxn( const void* aa, const void* bb ){
char* a = (char*)(aa);
char* b = (char*)(bb);
int l2 = strlen(b);
int min = strlen(a);
if( l2 < min ){ min = l2; }
int i = 0;
for(; i < min; i++){
if( a[i] < b[i] ){ return 0;
}
if( a[i] > b[i] ){ return 1;
}
}
if( l2 > min ){ return 0; }
return 1;
}
int intToStr( int input, char out[] ){
//end with \0
char temp[100];
int i = 0;
while(input != 0 ){
temp[i++] = (input%10 + '0')
;
input = input/10;
}
i--;
int j = 0;
for(; i>= 0; i-- ){
out[j++] = temp[i];
}
out[j] = '\0';
}
int main(){
char Orignames[100][50];
char names[100][50];
int totalPlayers = 0;
char inp[200];
while( scanf("%s", inp ) != EOF ){
char name[10];
int score = parse_input( inp , name
);
int i = 0;
char tempo[100];
intToStr( score, tempo );
for(; i < totalPlayers;
i++){
if(
isMatch(name, Orignames[i] ) ){
int len = strlen(names[i]);
names[i][ len ] = ':';
names[i][ len+1 ] = '\0';
cpyCharArray( names[i] + len+1 , tempo);
break;
}
}
if( i == totalPlayers ){
cpyCharArray(
names[ totalPlayers ] , name );
cpyCharArray(
Orignames[ totalPlayers ] , name );
int len =
strlen(names[i]);
names[i][ len ]
= ':';
names[i][ len+1
] = '\0';
cpyCharArray(
names[i] + len+1 , tempo);
totalPlayers++;
}
}
qsort( names, totalPlayers, 50 , cmpFxn );
int i = 0;
for(; i < totalPlayers; i++){
printf("%s\n", names[i] );
}
return 0;
}
Need help, a bit confused. Thank you. 2) (10 points) Assuming there is an offline game,...
need help, dont understand how to set up. 1 You are a game developer at Microsoft Corporation and are charged with the task of developing games in C++. 2 Please develop a Rock Paper Scissor game for two players. Each player should have one of the following options: • 1. Rock • 2. Paper • 3. Scissor A. Player One: person You need to ask the person to enter one option from the above three. 10 B. Player Two: computer...
For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...
This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...
This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...