Skip to content

Instantly share code, notes, and snippets.

@Gofilord
Created December 19, 2014 13:21
Show Gist options
  • Save Gofilord/15fffe1a0f6c9b694d24 to your computer and use it in GitHub Desktop.
Save Gofilord/15fffe1a0f6c9b694d24 to your computer and use it in GitHub Desktop.
public static void main(string[] args)
{
// let's say there are 10 boys, 11 girls and each girl gets to choose 5
const int BOY_AMOUNT = 10;
const int GIRL_AMOUNT = 11;
const int CHOICE_AMOUNT = 5;
// indexes are serial numbers and the values are their scores
int[] boys = new int[BOY_AMOUNT];
// init boys
for (int i = 0; i < boys.Length(); i++)
boys[i] = 0;
// looping through all the girls
// to get their score on each of the ten boys
for (int i = 0; i < GIRL_AMOUNT; i++)
{
int serial, score;
// looping through all the boys for this girl
for (int j = 0; j < CHOICE_AMOUNT; j++)
{
Console.WriteLine(i + ") enter boy's serial number: ");
serial = int.parse(Console.ReadLine());
Console.WriteLine(i + ") enter boy's score: ");
score = int.parse(Console.ReadLine());
boys[serial] = score;
}
}
/// finding the prom king and who didn't get invited at all
int king = 1; // that's the lowest score
int looserAmount = 0; // for the amount of boys no one chose
for (int i = 0; i < boys.Length; i++)
{
// finding the max score ("king")
if (boys[i] > king)
king = boys[i];
// find how much boys have a score of 0
// which means they got no score at all
if (boys[i] == 0)
looserAmount++;
}
// printing the results
Console.WriteLine("Prom king: " + king);
Console.WriteLine("Amount of people that no one asked: " + looserAmount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment