Skip to content

Instantly share code, notes, and snippets.

@Filkolev
Last active March 11, 2019 19:38
Show Gist options
  • Save Filkolev/49e15e9403ba001958a1a7fcd57d7188 to your computer and use it in GitHub Desktop.
Save Filkolev/49e15e9403ba001958a1a7fcd57d7188 to your computer and use it in GitHub Desktop.
Programming Basics Online Exam - 9 and 10 March 2019
using System;
class Program
{
static void Main(string[] args)
{
int annualFee = int.Parse(Console.ReadLine());
double priceOfSneakers = annualFee * 0.6;
double priceOfClothes = priceOfSneakers * 0.8;
double priceOfBasketball = priceOfClothes / 4;
double priceOfAccessories = priceOfBasketball / 5;
double totalPrice = annualFee + priceOfSneakers + priceOfClothes + priceOfBasketball + priceOfAccessories;
Console.WriteLine($"{totalPrice:f2}");
}
}
using System;
class Program
{
static void Main(string[] args)
{
int totalMatches = 0;
int matchesWon = 0;
string command = Console.ReadLine();
while (command != "End of tournaments")
{
string tournament = command;
int matches = int.Parse(Console.ReadLine());
totalMatches += matches;
for (int currentMatch = 1; currentMatch <= matches; currentMatch++)
{
int desiScore = int.Parse(Console.ReadLine());
int oponentScore = int.Parse(Console.ReadLine());
if (desiScore > oponentScore)
{
matchesWon++;
int diff = desiScore - oponentScore;
Console.WriteLine($"Game {currentMatch} of tournament {tournament}: win with {diff} points.");
}
else
{
int diff = oponentScore - desiScore;
Console.WriteLine($"Game {currentMatch} of tournament {tournament}: lost with {diff} points.");
}
}
command = Console.ReadLine().Trim();
}
double percentWon = 100.0 * matchesWon / totalMatches;
double percentLost = 100 - percentWon;
Console.WriteLine($"{percentWon:f2}% matches win");
Console.WriteLine($"{percentLost:f2}% matches lost");
}
}
using System;
class Program
{
static void Main(string[] args)
{
string name = Console.ReadLine();
int points = 301;
int successfulShots = 0;
int unsuccessfulShots = 0;
string command = Console.ReadLine();
while (command != "Retire")
{
string field = command;
int currentPoints = int.Parse(Console.ReadLine());
if (field == "Double")
{
currentPoints *= 2;
}
else if (field == "Triple")
{
currentPoints *= 3;
}
if (currentPoints <= points && currentPoints != 0)
{
points -= currentPoints;
successfulShots++;
}
else
{
unsuccessfulShots++;
}
if (points == 0)
{
break;
}
command = Console.ReadLine();
}
if (points == 0)
{
Console.WriteLine($"{name} won the leg with {successfulShots} shots.");
}
else
{
Console.WriteLine($"{name} retired after {unsuccessfulShots} unsuccessful shots.");
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
int numberOfVisitors = int.Parse(Console.ReadLine());
int countBack = 0;
int countChest = 0;
int countLegs = 0;
int countAbs = 0;
int countShake = 0;
int countBar = 0;
for (int i = 0; i < numberOfVisitors; i++)
{
string visitReason = Console.ReadLine();
switch (visitReason)
{
case "Back":
countBack++;
break;
case "Chest":
countChest++;
break;
case "Legs":
countLegs++;
break;
case "Abs":
countAbs++;
break;
case "Protein shake":
countShake++;
break;
case "Protein bar":
countBar++;
break;
}
}
int totalTraining = countBack + countChest + countLegs + countAbs;
int totalBuying = countShake + countBar;
double percentTraining = 100.0 * totalTraining / numberOfVisitors;
double percentBuying = 100.0 * totalBuying / numberOfVisitors;
Console.WriteLine($"{countBack} - back");
Console.WriteLine($"{countChest} - chest");
Console.WriteLine($"{countLegs} - legs");
Console.WriteLine($"{countAbs} - abs");
Console.WriteLine($"{countShake} - protein shake");
Console.WriteLine($"{countBar} - protein bar");
Console.WriteLine($"{percentTraining:f2}% - work out");
Console.WriteLine($"{percentBuying:f2}% - protein");
}
}
using System;
class Program
{
static void Main(string[] args)
{
int countWins = 0;
int countLosses = 0;
int countDraws = 0;
for (int i = 0; i < 3; i++)
{
string result = Console.ReadLine();
int goalsScored = result[0] - '0';
int goalsReceived = result[2] - '0';
if (goalsScored > goalsReceived)
{
countWins++;
}
else if (goalsScored == goalsReceived)
{
countDraws++;
}
else
{
countLosses++;
}
}
Console.WriteLine($"Team won {countWins} games.");
Console.WriteLine($"Team lost {countLosses} games.");
Console.WriteLine($"Drawn games: {countDraws}");
}
}
using System;
class Program
{
static void Main(string[] args)
{
string firstPlayer = Console.ReadLine();
string secondPlayer = Console.ReadLine();
int firstPlayerPoints = 0;
int secondPlayerPoints = 0;
string winner = string.Empty;
int winnerPoints = 0;
string command = Console.ReadLine();
while (command != "End of game")
{
int firstPlayerCard = int.Parse(command);
int secondPlayerCard = int.Parse(Console.ReadLine());
if (firstPlayerCard > secondPlayerCard)
{
firstPlayerPoints += firstPlayerCard - secondPlayerCard;
}
else if (secondPlayerCard > firstPlayerCard)
{
secondPlayerPoints += secondPlayerCard - firstPlayerCard;
}
else
{
Console.WriteLine("Number wars!");
firstPlayerCard = int.Parse(Console.ReadLine());
secondPlayerCard = int.Parse(Console.ReadLine());
if (firstPlayerCard > secondPlayerCard)
{
winner = firstPlayer;
winnerPoints = firstPlayerPoints;
}
else
{
winner = secondPlayer;
winnerPoints = secondPlayerPoints;
}
break;
}
command = Console.ReadLine();
}
if (winner != string.Empty)
{
Console.WriteLine($"{winner} is winner with {winnerPoints} points");
}
else
{
Console.WriteLine($"{firstPlayer} has {firstPlayerPoints} points");
Console.WriteLine($"{secondPlayer} has {secondPlayerPoints} points");
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
string country = Console.ReadLine();
string item = Console.ReadLine();
double score = 0;
switch (country)
{
case "Russia":
switch (item)
{
case "ribbon":
score = 9.1 + 9.4;
break;
case "hoop":
score = 9.3 + 9.8;
break;
case "rope":
score = 9.6 + 9;
break;
}
break;
case "Bulgaria":
switch (item)
{
case "ribbon":
score = 9.6 + 9.4;
break;
case "hoop":
score = 9.55 + 9.75;
break;
case "rope":
score = 9.5 + 9.4;
break;
}
break;
case "Italy":
switch (item)
{
case "ribbon":
score = 9.2 + 9.5;
break;
case "hoop":
score = 9.45 + 9.35;
break;
case "rope":
score = 9.7 + 9.15;
break;
}
break;
}
Console.WriteLine($"The team of {country} get {score:f3} on {item}.");
double maxScore = 20;
double percentLessThanPerfect = (maxScore - score) / maxScore * 100;
Console.WriteLine($"{percentLessThanPerfect:f2}%");
}
}
using System;
class Program
{
static void Main(string[] args)
{
int targetHeight = int.Parse(Console.ReadLine());
int currentHeight = targetHeight - 30;
int totalJumps = 0;
bool successfulJump = false;
while (true)
{
successfulJump = false;
for (int i = 0; i < 3; i++)
{
int currentJumpHeight = int.Parse(Console.ReadLine());
totalJumps++;
if (currentJumpHeight > currentHeight)
{
successfulJump = true;
break;
}
}
if (!successfulJump || currentHeight >= targetHeight)
{
break;
}
currentHeight += 5;
}
if (!successfulJump)
{
Console.WriteLine($"Tihomir failed at {currentHeight}cm after {totalJumps} jumps.");
}
else
{
Console.WriteLine($"Tihomir succeeded, he jumped over {currentHeight}cm after {totalJumps} jumps.");
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
int quotaMinutes = int.Parse(Console.ReadLine());
int quotaSeconds = int.Parse(Console.ReadLine());
double lengthOfTrackInMeters = double.Parse(Console.ReadLine());
int secondsPer100Meters = int.Parse(Console.ReadLine());
int quotaTotalSeconds = quotaMinutes * 60 + quotaSeconds;
double secondsToCompleteTrack = secondsPer100Meters * (lengthOfTrackInMeters / 100);
double secondsReducedDueToTrackSlope = (lengthOfTrackInMeters / 120) * 2.5;
secondsToCompleteTrack -= secondsReducedDueToTrackSlope;
if (secondsToCompleteTrack <= quotaTotalSeconds)
{
Console.WriteLine("Marin Bangiev won an Olympic quota!");
Console.WriteLine($"His time is {secondsToCompleteTrack:f3}.");
}
else
{
double secondsAboveQuota = secondsToCompleteTrack - quotaTotalSeconds;
Console.WriteLine($"No, Marin failed! He was {secondsAboveQuota:f3} second slower.");
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
double priceOfRacket = double.Parse(Console.ReadLine());
int numberOfRackets = int.Parse(Console.ReadLine());
int numberOfShoePairs = int.Parse(Console.ReadLine());
double pricePerShoePair = priceOfRacket / 6;
double totalPriceOfRackets = priceOfRacket * numberOfRackets;
double totalPriceOfShoes = pricePerShoePair * numberOfShoePairs;
double priceOfAccessories = 0.2 * (totalPriceOfRackets + totalPriceOfShoes);
double totalPrice = totalPriceOfRackets + totalPriceOfShoes + priceOfAccessories;
double paidByDjokovic = Math.Floor(totalPrice / 8);
double paidBySponsors = Math.Ceiling(totalPrice * 7 / 8);
Console.WriteLine($"Price to be paid by Djokovic {paidByDjokovic}");
Console.WriteLine($"Price to be paid by sponsors {paidBySponsors}");
}
}
using System;
class Program
{
static void Main(string[] args)
{
int numberOfTournaments = int.Parse(Console.ReadLine());
int pointsAtStartOfSeason = int.Parse(Console.ReadLine());
int pointsInCurrentSeason = 0;
int tournamentsWon = 0;
for (int i = 0; i < numberOfTournaments; i++)
{
string stageReached = Console.ReadLine();
switch (stageReached)
{
case "W":
tournamentsWon++;
pointsInCurrentSeason += 2000;
break;
case "F":
pointsInCurrentSeason += 1200;
break;
case "SF":
pointsInCurrentSeason += 720;
break;
}
}
int pointsAtEndOfSeason = pointsAtStartOfSeason + pointsInCurrentSeason;
int averagePoints = pointsInCurrentSeason / numberOfTournaments;
double percentTournamentsWon = 100.0 * tournamentsWon / numberOfTournaments;
Console.WriteLine($"Final points: {pointsAtEndOfSeason}");
Console.WriteLine($"Average points: {averagePoints}");
Console.WriteLine($"{percentTournamentsWon:f2}%");
}
}
using System;
class Program
{
static void Main(string[] args)
{
string competitionStage = Console.ReadLine();
string ticketType = Console.ReadLine();
int numberOfTickets = int.Parse(Console.ReadLine());
string photoOption = Console.ReadLine();
double pricePerTicket = 0;
switch (competitionStage)
{
case "Quarter final":
switch (ticketType)
{
case "Standard":
pricePerTicket = 55.5;
break;
case "Premium":
pricePerTicket = 105.2;
break;
case "VIP":
pricePerTicket = 118.9;
break;
}
break;
case "Semi final":
switch (ticketType)
{
case "Standard":
pricePerTicket = 75.88;
break;
case "Premium":
pricePerTicket = 125.22;
break;
case "VIP":
pricePerTicket = 300.4;
break;
}
break;
case "Final":
switch (ticketType)
{
case "Standard":
pricePerTicket = 110.1;
break;
case "Premium":
pricePerTicket = 160.66;
break;
case "VIP":
pricePerTicket = 400;
break;
}
break;
}
double totalPrice = pricePerTicket * numberOfTickets;
bool freePhotos = false;
if (totalPrice > 4000)
{
totalPrice *= 0.75;
freePhotos = true;
}
else if (totalPrice > 2500)
{
totalPrice *= 0.9;
}
if (photoOption == "Y" && !freePhotos)
{
totalPrice += numberOfTickets * 40;
}
Console.WriteLine($"{totalPrice:f2}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment