├── .gitignore ├── C# ├── 2048.cs ├── apaxiaaans.cs ├── autori.cs ├── batterup.cs ├── bela.cs ├── bijele.cs ├── boatparts.cs ├── carrots.cs ├── cd.cs ├── cetvrta.cs ├── cold.cs ├── conundrum.cs ├── cups.cs ├── datum.cs ├── dicecup.cs ├── drmmessages.cs ├── easiest.cs ├── erraticants.cs ├── everywhere.cs ├── faktor.cs ├── filip.cs ├── fizzbuzz.cs ├── grassseed.cs ├── hello.cs ├── hissingmicrophone.cs ├── icpcawards.cs ├── judgingmoose.cs ├── kitten.cs ├── ladder.cs ├── lineup.cs ├── metaprogramming.cs ├── nastyhacks.cs ├── nodup.cs ├── numberfun.cs ├── oddgnome.cs ├── oddities.cs ├── oddmanout.cs ├── parking2.cs ├── pet.cs ├── planina.cs ├── pot.cs ├── ptice.cs ├── quadrant.cs ├── r2.cs ├── railroad2.cs ├── reversebinary.cs ├── reverserot.cs ├── server.cs ├── sevenwonders.cs ├── sibice.cs ├── simpleaddition.cs ├── skener.cs ├── skocimis.cs ├── soylent.cs ├── spavanac.cs ├── speedlimit.cs ├── stararrangements.cs ├── symmetricorder.cs ├── tarifa.cs ├── tetration.cs ├── timeloop.cs ├── tolower.cs ├── touchscreenkeyboard.cs ├── trik.cs ├── trollhunt.cs ├── zamka.cs └── zanzibar.cs ├── C++ ├── akcija.cpp ├── alphabetanimals.cpp ├── anewalphabet.cpp ├── areal.cpp ├── babybites.cpp ├── beatspread.cpp ├── beautifulprimes.cpp ├── beavergnaw.cpp ├── bitbybit.cpp ├── bits.cpp ├── brokenswords.cpp ├── climbingworm.cpp ├── compass.cpp ├── conquestcampaign.cpp ├── convexpolygonarea.cpp ├── cudoviste.cpp ├── dasblinkenlights.cpp ├── dicegame.cpp ├── divideby100.cpp ├── dreamer.cpp ├── egypt.cpp ├── erraticants.cpp ├── fallingapart.cpp ├── fiftyshades.cpp ├── freefood.cpp ├── fundamentalneighbors.cpp ├── gcpc.cpp ├── goatrope.cpp ├── greedilyincreasing.cpp ├── grid.cpp ├── harshadnumbers.cpp ├── heartrate.cpp ├── heirsdilemma.cpp ├── hindex.cpp ├── howl.cpp ├── howmanydigits.cpp ├── humancannonball2.cpp ├── knightjump.cpp ├── krizaljka.cpp ├── leftbeehind.cpp ├── licensetolaunch.cpp ├── limbo1.cpp ├── loworderzeros.cpp ├── luhnchecksum.cpp ├── marko.cpp ├── mathhomework.cpp ├── nonprimefactors.cpp ├── nsum.cpp ├── numbertree.cpp ├── pascal.cpp ├── patuljci.cpp ├── pauleigon.cpp ├── primaryarithmetic.cpp ├── princesspeach.cpp ├── printingcosts.cpp ├── provincesandgold.cpp ├── prozor.cpp ├── prsteni.cpp ├── prva.cpp ├── relocation.cpp ├── sodaslurper.cpp ├── sok.cpp ├── statistics.cpp ├── stringmatching.cpp ├── sumoftheothers.cpp ├── thelastproblem.cpp ├── veci.cpp └── volim.cpp ├── C ├── electricaloutlets.c ├── finalexam2.c ├── greetings2.c ├── heimavinna.c ├── ofugsnuid.c ├── savingforretirement.c ├── sifferprodukt.c └── tornbygge.c ├── Java ├── 10kindsofpeople.java ├── 2048.java ├── 4thought.java ├── aaah.java ├── abc.java ├── aboveaverage.java ├── acm.java ├── addemup.java ├── addingwords.java ├── almostperfect.java ├── alphabetspam.java ├── anagramcounting.java ├── anothercandies.java ├── apaxiaaans.java ├── apaxianparent.java ├── apples.java ├── arithmetic.java ├── artichoke.java ├── astro.java ├── automatictrading.java ├── autori.java ├── averagespeed.java ├── avion.java ├── babelfish.java ├── babylonian.java ├── backspace.java ├── baconeggsandspam.java ├── baloni.java ├── bard.java ├── basketballoneonone.java ├── batterup.java ├── beautifulprimes.java ├── beehouseperimeter.java ├── beekeeper.java ├── bela.java ├── bijele.java ├── bing.java ├── birds.java ├── blockcrusher.java ├── boatparts.java ├── bookingaroom.java ├── bus.java ├── busnumbers.java ├── carrots.java ├── cd.java ├── cetvrta.java ├── chanukah.java ├── chartingprogress.java ├── checkingforcorrectness.java ├── classy.java ├── coast.java ├── cold.java ├── combinationlock.java ├── compoundwords.java ├── conundrum.java ├── costumecontest.java ├── countingstars.java ├── cups.java ├── datum.java ├── deathknight.java ├── deduplicatingfiles.java ├── detaileddifferences.java ├── dicecup.java ├── different.java ├── differentdistances.java ├── digits.java ├── display.java ├── dominoes2.java ├── downtime.java ├── drmmessages.java ├── dst.java ├── easiest.java ├── election.java ├── elevatortrouble.java ├── encodedmessage.java ├── engineeringenglish.java ├── epigdanceoff.java ├── erase.java ├── erraticants.java ├── estimatingtheareaofacircle.java ├── eulersnumber.java ├── everywhere.java ├── faktor.java ├── falsesecurity.java ├── fenwick.java ├── filip.java ├── firefly.java ├── fizzbuzz.java ├── flipfive.java ├── freefood.java ├── fridge.java ├── froshweek2.java ├── frosting.java ├── gerrymandering.java ├── grassseed.java ├── guess.java ├── guessinggame.java ├── guessthedatastructure.java ├── hangingout.java ├── hangman.java ├── happyprime.java ├── hello.java ├── helpaphd.java ├── herman.java ├── hidden.java ├── hissingmicrophone.java ├── hothike.java ├── htoo.java ├── icpcawards.java ├── integerdivision.java ├── isithalloween.java ├── islands.java ├── islands3.java ├── iwannabe.java ├── janitortroubles.java ├── jobexpenses.java ├── judgingmoose.java ├── justaminute.java ├── karte.java ├── kemija08.java ├── kornislav.java ├── ladder.java ├── lastfactorialdigit.java ├── limbo1.java ├── listgame.java ├── lostlineup.java ├── mastermind.java ├── mirror.java ├── missingnumbers.java ├── mixedfractions.java ├── mjehuric.java ├── modulo.java ├── moscowdream.java ├── mosquito.java ├── musicyourway.java ├── nastyhacks.java ├── natrij.java ├── nodup.java ├── npuzzle.java ├── numberfun.java ├── oddgnome.java ├── oddities.java ├── oddmanout.java ├── okviri.java ├── onechicken.java ├── ostgotska.java ├── owlandfox.java ├── pachydermpeanutpacking.java ├── pairingsocks.java ├── palindromicpassword.java ├── parking.java ├── parking2.java ├── parsinghex.java ├── perket.java ├── permutedarithmeticsequence.java ├── pet.java ├── phonelist.java ├── pieceofcake2.java ├── pizza2.java ├── planina.java ├── platforme.java ├── pokerhand.java ├── pot.java ├── primalrepresentation.java ├── primematrix.java ├── primereduction.java ├── program.java ├── ptice.java ├── qaly.java ├── quadrant.java ├── quickbrownfox.java ├── quickestimate.java ├── r2.java ├── racingalphabet.java ├── raggedright.java ├── railroad2.java ├── rationalsequence2.java ├── reachableroads.java ├── recipes.java ├── recount.java ├── rectanglesurrounding.java ├── redsocks.java ├── repeatingdecimal.java ├── reseto.java ├── reversebinary.java ├── reverserot.java ├── rijeci.java ├── rings2.java ├── rollcall.java ├── romans.java ├── runlengthencodingrun.java ├── savingdaylight.java ├── scrollingsign.java ├── sevenwonders.java ├── shatteredcake.java ├── shopaholic.java ├── shortestpath1.java ├── sibice.java ├── sidewayssorting.java ├── simon.java ├── simonsays.java ├── simplicity.java ├── skener.java ├── skocimis.java ├── slatkisi.java ├── slikar.java ├── smallestmultiple.java ├── softpasswords.java ├── somesum.java ├── sortofsorting.java ├── soylent.java ├── soyoulikeyourfoodhot.java ├── spavanac.java ├── speedlimit.java ├── stararrangements.java ├── stringmatching.java ├── sumkindofproblem.java ├── sumoftheothers.java ├── sumsquareddigits.java ├── supercomputer.java ├── symmetricorder.java ├── synchronizinglists.java ├── taisformula.java ├── tarifa.java ├── teacherevaluation.java ├── tetration.java ├── textureanalysis.java ├── thebackslashproblem.java ├── thegrandadventure.java ├── thisaintyourgrandpascheckerboard.java ├── throwns.java ├── timeloop.java ├── tiredterry.java ├── tolower.java ├── torn2pieces.java ├── touchscreenkeyboard.java ├── towering.java ├── tri.java ├── trik.java ├── tripletexting.cpp ├── turtlemaster.java ├── twostones.java ├── unionfind.java ├── unlockpattern.java ├── vacuumba.java ├── variablearithmetic.java ├── vote.java ├── wheresmyinternet.java ├── wordsfornumbers.java ├── yoda.java ├── zamka.java ├── zanzibar.java └── zoo.java ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.exe 3 | *.txt 4 | generator/ 5 | .vscode 6 | wip/ -------------------------------------------------------------------------------- /C#/apaxiaaans.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class apaxiaaans { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | string last = ""; 7 | for (int x = 0; x < line.Length - 1; x++) 8 | if (line[x] != line[x + 1]) 9 | last += line[x]; 10 | Console.WriteLine (last + line[line.Length - 1]); 11 | } 12 | } -------------------------------------------------------------------------------- /C#/autori.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class autori { 4 | public static void Main (string[] args) { 5 | char[] name = Console.ReadLine ().ToCharArray (); 6 | bool isDash = false; 7 | Console.Write (name[0]); 8 | foreach (char s in name) { 9 | if (isDash) { 10 | Console.Write (s); 11 | isDash = false; 12 | } 13 | if (s == '-') 14 | isDash = true; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /C#/batterup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class batterup { 4 | public static void Main (string[] args) { 5 | double cases = int.Parse (Console.ReadLine ()); 6 | double total = 0; 7 | foreach (string s in Console.ReadLine ().Split (' ')) { 8 | if (!s.Equals ("-1") && !s.Equals ("0")) 9 | total += int.Parse (s); 10 | else if (s.Equals ("-1")) 11 | cases--; 12 | } 13 | Console.WriteLine (total / cases); 14 | } 15 | } -------------------------------------------------------------------------------- /C#/bijele.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class bijele { 4 | public static void Main (string[] args) { 5 | int[] ori = { 1, 1, 2, 2, 2, 8 }; 6 | int i = 0; 7 | foreach (string s in Console.ReadLine ().Split (' ')) 8 | Console.Write (ori[i++] - int.Parse (s) + " "); 9 | } 10 | } -------------------------------------------------------------------------------- /C#/boatparts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class boatparts { 5 | public static void Main (string[] args) { 6 | string[] line = Console.ReadLine ().Split (' '); 7 | int total = int.Parse (line[0]); 8 | int days = int.Parse (line[1]); 9 | bool found = false; 10 | SortedSet parts = new SortedSet (); 11 | for (int x = 1; x <= days; x++) { 12 | parts.Add (Console.ReadLine ()); 13 | if (parts.Count == total) { 14 | Console.WriteLine (x); 15 | found = true; 16 | break; 17 | } 18 | } 19 | if (!found) 20 | Console.WriteLine ("paradox avoided"); 21 | } 22 | } -------------------------------------------------------------------------------- /C#/carrots.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class carrots { 4 | public static void Main (string[] args) { 5 | string[] nums = Console.ReadLine ().Split (' '); 6 | int num = int.Parse (nums[0]); 7 | while (num-- > 0) 8 | Console.ReadLine (); 9 | Console.WriteLine (nums[1]); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/cd.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class cd { 5 | public static void Main (string[] args) { 6 | for (;;) { 7 | string[] line = Console.ReadLine ().Split (' '); 8 | if (line[0].Equals ("0") && line[1].Equals ("0")) 9 | break; 10 | int total = int.Parse (line[0]) + int.Parse (line[1]); 11 | HashSet cds = new HashSet (); 12 | for (int x = 0; x < total; x++) 13 | cds.Add (Console.ReadLine ()); 14 | Console.WriteLine (total - cds.Count); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /C#/cold.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class cold { 4 | public static void Main (string[] args) { 5 | Console.ReadLine (); 6 | string[] nums = Console.ReadLine ().Split (' '); 7 | int count = 0; 8 | foreach (string s in nums) 9 | if (s[0] == '-') 10 | count++; 11 | Console.WriteLine (count); 12 | } 13 | } -------------------------------------------------------------------------------- /C#/conundrum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class conundrum { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int day = 0; 7 | for (int x = 0; x < line.Length; x += 3) { 8 | if (line[x] != 'P') 9 | day++; 10 | if (line[x + 1] != 'E') 11 | day++; 12 | if (line[x + 2] != 'R') 13 | day++; 14 | } 15 | Console.WriteLine (day); 16 | } 17 | } -------------------------------------------------------------------------------- /C#/cups.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class cups { 5 | public static void Main (string[] args) { 6 | SortedDictionary sort = new SortedDictionary (); 7 | int cases = int.Parse (Console.ReadLine ()); 8 | while (cases-- > 0) { 9 | string[] line = Console.ReadLine ().Split (' '); 10 | string color; 11 | int d; 12 | if (line[0][0] >= '0' && line[0][0] <= '9') { 13 | color = line[1]; 14 | d = int.Parse (line[0]); 15 | } else { 16 | color = line[0]; 17 | d = int.Parse (line[1]) * 2; 18 | } 19 | sort.Add (d, color); 20 | } 21 | foreach (KeyValuePair s in sort) 22 | Console.WriteLine (s.Value); 23 | } 24 | } -------------------------------------------------------------------------------- /C#/datum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class datum { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int day = int.Parse (line.Substring (0, space)); 8 | int month = int.Parse (line.Substring (space + 1)); 9 | for (int x = 1; x < month; x++) { 10 | switch (x) { 11 | case 1: 12 | case 3: 13 | case 5: 14 | case 7: 15 | case 8: 16 | case 10: 17 | case 12: 18 | day += 31; 19 | break; 20 | case 2: 21 | day += 28; 22 | break; 23 | case 4: 24 | case 6: 25 | case 9: 26 | case 11: 27 | day += 30; 28 | break; 29 | } 30 | } 31 | day %= 7; 32 | Console.WriteLine (day == 0 ? "Wednesday" : day == 1 ? "Thursday" : day == 2 ? "Friday" : day == 3 ? "Saturday" : day == 4 ? "Sunday" : day == 5 ? "Monday" : "Tuesday"); 33 | } 34 | } -------------------------------------------------------------------------------- /C#/dicecup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class dicecup { 5 | public static void Main (string[] args) { 6 | string line = Console.ReadLine (); 7 | int space = line.IndexOf (' '); 8 | int die1 = int.Parse (line.Substring (0, space)); 9 | int die2 = int.Parse (line.Substring (space + 1)); 10 | int max = 0; 11 | SortedDictionary sums = new SortedDictionary (); 12 | for (int x = 1; x <= die1; x++) { 13 | for (int a = 1; a <= die2; a++) { 14 | int sum = a + x; 15 | if (sums.ContainsKey (sum)) 16 | sums[sum] = sums[sum] + 1; 17 | else 18 | sums.Add (sum, 1); 19 | 20 | if (sums[sum] > max) 21 | max = sums[sum]; 22 | } 23 | } 24 | foreach (KeyValuePair s in sums) 25 | if (s.Value == max) 26 | Console.WriteLine (s.Key); 27 | } 28 | } -------------------------------------------------------------------------------- /C#/drmmessages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class drmmessages { 4 | public static void Main (string[] args) { 5 | string msg = Console.ReadLine (); 6 | char[] fhalf = msg.Substring (0, msg.Length / 2).ToCharArray (); 7 | char[] shalf = msg.Substring (msg.Length / 2).ToCharArray (); 8 | string alpha = "abcdefghijklmnopqrstuvwxyz".ToUpper (); 9 | int change1 = 0; 10 | int change2 = 0; 11 | for (int x = 0; x < fhalf.Length; x++) { 12 | change1 += alpha.IndexOf (fhalf[x]); 13 | change2 += alpha.IndexOf (shalf[x]); 14 | } 15 | for (int x = 0; x < fhalf.Length; x++) { 16 | fhalf[x] = (char) (((fhalf[x] % 'A') + change1) % 26 + 'A'); 17 | shalf[x] = (char) (((shalf[x] % 'A') + change2) % 26 + 'A'); 18 | } 19 | for (int x = 0; x < fhalf.Length; x++) 20 | fhalf[x] = (char) (((fhalf[x] + shalf[x]) % 'A') % 26 + 'A'); 21 | Console.WriteLine (fhalf); 22 | } 23 | } -------------------------------------------------------------------------------- /C#/easiest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class easiest { 4 | public static void Main (string[] args) { 5 | for (;;) { 6 | int n = int.Parse (Console.ReadLine ()); 7 | if (n == 0) 8 | break; 9 | int sum = sumDigits (n); 10 | 11 | for (int x = 11;; x++) 12 | if (sum == sumDigits (x * n)) { 13 | Console.WriteLine (x); 14 | break; 15 | } 16 | } 17 | } 18 | private static int sumDigits (int a) { 19 | int sum = 0; 20 | while (a > 0) { 21 | sum += (a % 10); 22 | a /= 10; 23 | } 24 | return sum; 25 | } 26 | } -------------------------------------------------------------------------------- /C#/everywhere.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class everywhere { 5 | public static void Main (string[] args) { 6 | int cases = int.Parse (Console.ReadLine ()); 7 | while (cases-- > 0) { 8 | int num = int.Parse (Console.ReadLine ()); 9 | string[] cities = new string[num]; 10 | for (int x = 0; x < num; x++) 11 | cities[x] = Console.ReadLine (); 12 | Console.WriteLine (cities.Distinct ().Count ()); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /C#/faktor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class faktor { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int publish = int.Parse (line.Substring (0, space)); 8 | int impact = int.Parse (line.Substring (space + 1)) - 1; 9 | Console.WriteLine ((publish * impact) + 1); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/filip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class filip { 5 | public static void Main (string[] args) { 6 | string line = Console.ReadLine (); 7 | int space = line.IndexOf (' '); 8 | char[] digits1 = line.Substring (0, space).ToCharArray (); 9 | char[] digits2 = line.Substring (space + 1).ToCharArray (); 10 | Array.Reverse (digits1); 11 | Array.Reverse (digits2); 12 | string temp = ""; 13 | foreach (char s in digits1) 14 | temp += s + ""; 15 | int fnum = int.Parse (temp); 16 | temp = ""; 17 | foreach (char s in digits2) 18 | temp += s + ""; 19 | int snum = int.Parse (temp); 20 | Console.WriteLine(fnum > snum ? fnum : snum); 21 | } 22 | } -------------------------------------------------------------------------------- /C#/fizzbuzz.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class fizzbuzz { 4 | public static void Main (string[] args) { 5 | string[] line = Console.ReadLine ().Split (' '); 6 | int x = int.Parse (line[0]); 7 | int y = int.Parse (line[1]); 8 | int n = int.Parse (line[2]); 9 | for (int a = 1; a <= n; a++) 10 | Console.WriteLine (a % x == 0 && a % y == 0 ? "FizzBuzz" : a % x == 0 ? "Fizz" : a % y == 0 ? "Buzz" : a + ""); 11 | } 12 | } -------------------------------------------------------------------------------- /C#/grassseed.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class grassseed { 4 | public static void Main (string[] args) { 5 | double cost = double.Parse (Console.ReadLine ()); 6 | int cases = int.Parse (Console.ReadLine ()); 7 | double total = 0; 8 | while (cases-- > 0) { 9 | string line = Console.ReadLine (); 10 | int space = line.IndexOf (' '); 11 | double w = double.Parse (line.Substring (0, space)); 12 | double h = double.Parse (line.Substring (space + 1)); 13 | total += (w * h) * cost; 14 | } 15 | Console.WriteLine ("{0:0.0000000}", total); 16 | } 17 | } -------------------------------------------------------------------------------- /C#/hello.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class hello { 4 | public static void Main (string[] args) { 5 | Console.WriteLine ("Hello World!"); 6 | } 7 | } -------------------------------------------------------------------------------- /C#/hissingmicrophone.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class hissingmicrophone { 4 | public static void Main (string[] args) { 5 | Console.WriteLine (Console.ReadLine ().Contains ("ss") ? "hiss" : "no hiss"); 6 | } 7 | } -------------------------------------------------------------------------------- /C#/icpcawards.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class icpcawards { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | string[] teams = new string[12]; 7 | int i = 0; 8 | bool isDone = false; 9 | while (cases-- > 0) { 10 | string line = Console.ReadLine (); 11 | if (!isDone) { 12 | int space = line.IndexOf (' '); 13 | string uni = line.Substring (0, space); 14 | string team = line.Substring (space); 15 | bool seen = false; 16 | foreach (string s in teams) 17 | if (!String.IsNullOrEmpty (s) && s.Contains (uni)) { 18 | seen = true; 19 | break; 20 | } 21 | if (!seen) { 22 | teams[i++] = uni + team; 23 | if (i == 12) 24 | isDone = true; 25 | } 26 | } 27 | } 28 | foreach (string s in teams) 29 | Console.WriteLine (s); 30 | } 31 | } -------------------------------------------------------------------------------- /C#/judgingmoose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class judgingmoose { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int left = int.Parse (line.Substring (0, space)); 8 | int right = int.Parse (line.Substring (space + 1)); 9 | Console.WriteLine (left + right == 0 ? "Not a moose" : left == right ? "Even " + (right << 1) : "Odd " + (right > left ? right << 1 : left << 1)); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/kitten.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | public class kitten { 6 | public static void Main (string[] args) { 7 | string start = Console.ReadLine (); 8 | Dictionary, string> map = new Dictionary, string> (); 9 | for (;;) { 10 | string line = Console.ReadLine (); 11 | if (line.Equals ("-1")) 12 | break; 13 | int space = line.IndexOf (' '); 14 | map.Add (line.Substring (space + 1, line.Length - (space + 1)).Split (' ').ToList (), line.Substring (0, space)); 15 | } 16 | Console.Write (start + " "); 17 | bool done = false; 18 | while (!done) { 19 | done = true; 20 | foreach (KeyValuePair, string> s in map) 21 | if (s.Key.Contains (start)) { 22 | done = false; 23 | start = s.Value; 24 | break; 25 | } 26 | if (!done) 27 | Console.Write (start + " "); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /C#/ladder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class ladder { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | double height = double.Parse (line.Substring (0, space)); 8 | double degrees = double.Parse (line.Substring (space + 1)); 9 | Console.WriteLine ((int) Math.Ceiling (height / Math.Sin (degrees * (Math.PI / 180)))); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/lineup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class lineup { 5 | public static void Main (string[] args) { 6 | string[] arr = new string[int.Parse (Console.ReadLine ())]; 7 | for (int x = 0; x < arr.Length; x++) 8 | arr[x] = Console.ReadLine (); 9 | bool found = false; 10 | string[] copy = new string[arr.Length]; 11 | Array.Copy (arr, 0, copy, 0, copy.Length); 12 | Array.Sort (copy); 13 | if (Enumerable.SequenceEqual (arr, copy)) { 14 | Console.WriteLine ("INCREASING"); 15 | found = true; 16 | } 17 | Array.Sort (copy, (a, b) => b.CompareTo (a)); 18 | if (Enumerable.SequenceEqual (arr, copy)) { 19 | Console.WriteLine ("DECREASING"); 20 | found = true; 21 | } 22 | if (!found) 23 | Console.WriteLine ("NEITHER"); 24 | } 25 | } -------------------------------------------------------------------------------- /C#/metaprogramming.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class metaprogramming { 5 | public static void Main (string[] args) { 6 | Dictionary vars = new Dictionary (); 7 | 8 | string line; 9 | while ((line = Console.ReadLine ()) != null) { 10 | string[] arr = line.Split (' '); 11 | if (arr[0].Equals ("define")) 12 | if (vars.ContainsKey (arr[2])) 13 | vars[arr[2]] = int.Parse (arr[1]); 14 | else 15 | vars.Add (arr[2], int.Parse (arr[1])); 16 | else if (!(vars.ContainsKey (arr[1]) && vars.ContainsKey (arr[3]))) 17 | Console.WriteLine ("undefined"); 18 | else 19 | Console.WriteLine (arr[2].Equals (">") ? vars[arr[1]] > vars[arr[3]] : (arr[2].Equals ("<") ? vars[arr[1]] < vars[arr[3]] : vars[arr[1]] == vars[arr[3]])); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /C#/nastyhacks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class nastyhacks { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | string[] line = Console.ReadLine ().Split (' '); 8 | int noads = int.Parse (line[0]); 9 | int yesads = int.Parse (line[1]); 10 | int adcost = int.Parse (line[2]); 11 | Console.WriteLine (yesads - adcost > noads ? "advertise" : yesads - adcost == noads ? "does not matter" : "do not advertise"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /C#/nodup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class nodup { 5 | public static void Main (string[] args) { 6 | string[] words = Console.ReadLine ().Split (' '); 7 | Console.WriteLine (words.Distinct ().Count () != words.Count () ? "NO" : "YES"); 8 | } 9 | } -------------------------------------------------------------------------------- /C#/numberfun.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class numberfun { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | string[] line = Console.ReadLine ().Split (' '); 8 | double first = double.Parse (line[0]); 9 | double sec = double.Parse (line[1]); 10 | double thi = double.Parse (line[2]); 11 | if (first + sec == thi || first == sec + thi) 12 | Console.WriteLine ("Possible"); 13 | else if (first - sec == thi || first == sec - thi) 14 | Console.WriteLine ("Possible"); 15 | else if (first * sec == thi || first == sec * thi) 16 | Console.WriteLine ("Possible"); 17 | else if (first / sec == thi || first == sec / thi) 18 | Console.WriteLine ("Possible"); 19 | else 20 | Console.WriteLine ("Impossible"); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /C#/oddgnome.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class oddgnome { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | string[] line = Console.ReadLine ().Split (' '); 8 | int[] nums = new int[line.Length - 2]; 9 | for (int x = 0; x < nums.Length; x++) 10 | nums[x] = int.Parse (line[x + 1]); 11 | for (int x = 0; x < line.Length - 1; x++) 12 | if (nums[x] != nums[x + 1] - 1) { 13 | Console.WriteLine (x + 2); 14 | break; 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /C#/oddities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class oddities { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | int num = int.Parse (Console.ReadLine ()); 8 | Console.WriteLine ((Math.Abs (num) & 1) == 0 ? num + " is even" : num + " is odd"); 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /C#/oddmanout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class oddmanout { 5 | public static void Main (string[] args) { 6 | int cases = int.Parse (Console.ReadLine ()); 7 | for (int x = 1; x <= cases; x++) { 8 | Console.ReadLine (); 9 | List guests = new List (); 10 | foreach (string s in Console.ReadLine ().Split (' ')) { 11 | if (guests.Contains (s)) 12 | guests.Remove (s); 13 | else 14 | guests.Add (s); 15 | } 16 | Console.WriteLine ("Case #" + x + ": " + guests[0]); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /C#/parking2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class parking2 { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | int length = int.Parse (Console.ReadLine ()); 8 | int[] nums = new int[length]; 9 | int i = 0; 10 | foreach (string s in Console.ReadLine ().Split (' ')) 11 | nums[i++] = int.Parse (s); 12 | Array.Sort (nums); 13 | int total = nums[length - 1] - nums[0]; 14 | for (int x = 0; x < length - 1; x++) 15 | total += nums[x + 1] - nums[x]; 16 | Console.WriteLine (total); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /C#/pet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class pet { 4 | public static void Main (string[] args) { 5 | int max = 0; 6 | int index = 0; 7 | for (int x = 1; x <= 5; x++) { 8 | int sum = 0; 9 | foreach (string s in Console.ReadLine ().Split (' ')) 10 | sum += int.Parse (s); 11 | if (sum > max) { 12 | max = sum; 13 | index = x; 14 | } 15 | } 16 | Console.WriteLine (index + " " + max); 17 | } 18 | } -------------------------------------------------------------------------------- /C#/planina.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class planina { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | int points = 2; 7 | while (cases-- > 0) 8 | points += points - 1; 9 | Console.WriteLine ((int) Math.Pow (points, 2)); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/pot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class pot { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | int sum = 0; 7 | while (cases-- > 0) { 8 | string line = Console.ReadLine (); 9 | int num = int.Parse (line.Substring (0, line.Length - 1)); 10 | int pow = int.Parse (line.Substring (line.Length - 1)); 11 | sum += (int) Math.Pow (num, pow); 12 | } 13 | Console.WriteLine (sum); 14 | } 15 | } -------------------------------------------------------------------------------- /C#/ptice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class ptice { 4 | public static void Main (string[] args) { 5 | string a = "ABC"; 6 | string b = "BABC"; 7 | string g = "CCAABB"; 8 | int ac = 0, bc = 0, gc = 0; 9 | int i1 = 0, i2 = 0, i3 = 0; 10 | int high = 0; 11 | Console.ReadLine (); 12 | foreach (char c in Console.ReadLine ().ToCharArray ()) { 13 | if (c == a[i1]) 14 | ac++; 15 | if (c == b[i2]) 16 | bc++; 17 | if (c == g[i3]) 18 | gc++; 19 | i1 = i1 == 2 ? 0 : i1 + 1; 20 | i2 = i2 == 3 ? 0 : i2 + 1; 21 | i3 = i3 == 5 ? 0 : i3 + 1; 22 | high = ac > high ? ac : bc > high ? bc : gc > high ? gc : high; 23 | } 24 | Console.WriteLine (high); 25 | if (ac == high) 26 | Console.WriteLine ("Adrian"); 27 | if (bc == high) 28 | Console.WriteLine ("Bruno"); 29 | if (gc == high) 30 | Console.WriteLine ("Goran"); 31 | } 32 | } -------------------------------------------------------------------------------- /C#/quadrant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class quadrant { 4 | public static void Main (string[] args) { 5 | int x = int.Parse (Console.ReadLine ()); 6 | int y = int.Parse (Console.ReadLine ()); 7 | Console.WriteLine (x > 0 ? y > 0 ? 1 : 4 : y > 0 ? 2 : 3); 8 | } 9 | } -------------------------------------------------------------------------------- /C#/r2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class r2 { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int fnum = int.Parse (line.Substring (0, space)); 8 | int avg = int.Parse (line.Substring (space + 1)); 9 | Console.WriteLine ((avg * 2) - fnum); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/railroad2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class railroad2 { 4 | public static void Main (string[] args) { 5 | Console.WriteLine ((int.Parse (Console.ReadLine ().Split (' ') [1]) & 1) == 0 ? "possible" : "impossible"); 6 | } 7 | } -------------------------------------------------------------------------------- /C#/reversebinary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class reversebinary { 4 | public static void Main (string[] args) { 5 | string binary = Convert.ToString (int.Parse (Console.ReadLine ()), 2); 6 | string flip = ""; 7 | for (int x = binary.Length - 1; x >= 0; x--) 8 | flip += binary[x]; 9 | Console.WriteLine (Convert.ToInt32 (flip, 2)); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/reverserot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class reverserot { 4 | public static void Main (string[] args) { 5 | string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_."; 6 | for (;;) { 7 | string[] line = Console.ReadLine ().Split (' '); 8 | int rot = int.Parse (line[0]); 9 | if (rot == 0) 10 | break; 11 | string msg = line[1]; 12 | string s = ""; 13 | for (int x = msg.Length - 1; x >= 0; x--) 14 | for (int a = 0; a < alpha.Length; a++) 15 | if (alpha[a] == msg[x]) { 16 | s += alpha[(a + rot) % alpha.Length]; 17 | break; 18 | } 19 | Console.WriteLine (s); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /C#/server.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class server { 4 | public static void Main (string[] args) { 5 | int time = int.Parse (Console.ReadLine ().Split (' ') [1]); 6 | int sum = 0, count = 0; 7 | foreach (string s in Console.ReadLine ().Split (' ')) { 8 | sum += int.Parse (s); 9 | if (sum > time) 10 | break; 11 | count++; 12 | } 13 | Console.WriteLine (count); 14 | } 15 | } -------------------------------------------------------------------------------- /C#/sevenwonders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class sevenwonders { 4 | public static void Main (string[] args) { 5 | int t = 0; 6 | int c = 0; 7 | int g = 0; 8 | string line = Console.ReadLine (); 9 | for (int x = 0; x < line.Length; x++) { 10 | if (line[x] == 'T') 11 | t++; 12 | else if (line[x] == 'C') 13 | c++; 14 | else 15 | g++; 16 | } 17 | int min = t <= c && t <= g ? t : c <= t && c <= g ? c : g; 18 | Console.WriteLine ((int) (Math.Pow (t, 2) + Math.Pow (c, 2) + Math.Pow (g, 2) + (min * 7))); 19 | } 20 | } -------------------------------------------------------------------------------- /C#/sibice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class sibice { 4 | public static void Main (string[] args) { 5 | string[] nums = Console.ReadLine ().Split (' '); 6 | int cases = int.Parse (nums[0]); 7 | double hypot = Math.Sqrt (Math.Pow (int.Parse (nums[1]), 2) + Math.Pow (int.Parse (nums[2]), 2)); 8 | while (cases-- > 0) 9 | Console.WriteLine (int.Parse (Console.ReadLine ()) <= hypot ? "DA" : "NE"); 10 | } 11 | } -------------------------------------------------------------------------------- /C#/simpleaddition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class simpleaddition { 4 | public static void Main (string[] args) { 5 | string first = Console.ReadLine (); 6 | string second = Console.ReadLine (); 7 | int carry = 0; 8 | int a = first.Length - 1, b = second.Length - 1; 9 | string sum = ""; 10 | for (; a >= 0 && b >= 0; a--, b--) { 11 | int num = int.Parse (first[a] + "") + int.Parse (second[b] + "") + carry; 12 | sum = num % 10 + sum; 13 | carry = num / 10; 14 | } 15 | for (; a >= 0; a--) { 16 | int num = int.Parse (first[a] + "") + carry; 17 | sum = num % 10 + sum; 18 | carry = num / 10; 19 | } 20 | for (; b >= 0; b--) { 21 | int num = int.Parse (second[b] + "") + carry; 22 | sum = num % 10 + sum; 23 | carry = num / 10; 24 | } 25 | if (carry != 0) 26 | sum = carry + sum; 27 | Console.WriteLine (sum); 28 | } 29 | } -------------------------------------------------------------------------------- /C#/skener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class skener { 4 | public static void Main (string[] args) { 5 | string[] line = Console.ReadLine ().Split (' '); 6 | int lines = int.Parse (line[0]); 7 | while (lines-- > 0) { 8 | char[] current = Console.ReadLine ().ToCharArray (); 9 | for (int s = 0; s < int.Parse (line[2]); s++) { 10 | for (int x = 0; x < current.Length; x++) { 11 | for (int a = 0; a < int.Parse (line[3]); a++) 12 | Console.Write (current[x]); 13 | } 14 | Console.WriteLine (); 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /C#/skocimis.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class skocimis { 4 | public static void Main (string[] args) { 5 | string[] line = Console.ReadLine ().Split (' '); 6 | int a = int.Parse (line[0]); 7 | int b = int.Parse (line[1]); 8 | int c = int.Parse (line[2]); 9 | int max = Math.Max (b - a - 1, c - b - 1); 10 | Console.WriteLine (max); 11 | } 12 | } -------------------------------------------------------------------------------- /C#/soylent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class soylent { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | int cal = int.Parse (Console.ReadLine ()); 8 | Console.WriteLine (cal % 400 == 0 ? cal / 400 : (cal / 400) + 1); 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /C#/spavanac.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class spavanac { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int hour = int.Parse (line.Substring (0, space)); 8 | int min = int.Parse (line.Substring (space + 1)) - 45; 9 | if (min < 0) { 10 | min += 60; 11 | hour--; 12 | if (hour < 0) 13 | hour = 23; 14 | } 15 | Console.WriteLine (hour + " " + min); 16 | } 17 | } -------------------------------------------------------------------------------- /C#/speedlimit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class speedlimit { 4 | public static void Main (string[] args) { 5 | for (;;) { 6 | int cases = int.Parse (Console.ReadLine ()); 7 | if (cases == -1) 8 | break; 9 | int[] nums = new int[cases * 2]; 10 | for (int x = 0; x < nums.Length; x += 2) { 11 | string line = Console.ReadLine (); 12 | int space = line.IndexOf (' '); 13 | nums[x] = int.Parse (line.Substring (0, space)); 14 | nums[x + 1] = int.Parse (line.Substring (space + 1)); 15 | } 16 | int distance = nums[0] * nums[1]; 17 | for (int x = 2; x < nums.Length; x += 2) 18 | distance += nums[x] * (nums[x + 1] - nums[x - 1]); 19 | Console.WriteLine (distance + " miles"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /C#/stararrangements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class stararrangements { 4 | public static void Main (string[] args) { 5 | int stars = int.Parse (Console.ReadLine ()); 6 | Console.WriteLine (stars + ":"); 7 | for (int x = 2; x <= (stars / 2) + 1; x++) { 8 | if (stars % (x + (x - 1)) == x || stars % (x + (x - 1)) == 0) 9 | Console.WriteLine (x + "," + (x - 1)); 10 | if (stars % x == 0) 11 | Console.WriteLine (x + "," + x); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /C#/symmetricorder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class symmetricorder { 4 | public static void Main (string[] args) { 5 | for (int set = 1;; set++) { 6 | int cases = int.Parse (Console.ReadLine ()); 7 | if (cases == 0) 8 | break; 9 | Console.WriteLine ("SET " + set); 10 | string[] names = new string[cases]; 11 | int x = 0; 12 | for (int y = names.Length - 1; x < cases / 2; x++, y--) { 13 | names[x] = Console.ReadLine (); 14 | names[y] = Console.ReadLine (); 15 | } 16 | if ((cases & 1) != 0) 17 | names[x] = Console.ReadLine (); 18 | foreach (string s in names) 19 | Console.WriteLine (s); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /C#/tarifa.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class tarifa { 4 | public static void Main (string[] args) { 5 | int mb = int.Parse (Console.ReadLine ()); 6 | int months = int.Parse (Console.ReadLine ()); 7 | int spare = 0; 8 | while (months-- > 0) 9 | spare += mb - int.Parse (Console.ReadLine ()); 10 | Console.WriteLine (spare + mb); 11 | } 12 | } -------------------------------------------------------------------------------- /C#/tetration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class tetration { 4 | public static void Main (string[] args) { 5 | double num = double.Parse (Console.ReadLine ()); 6 | Console.WriteLine ("{0:0.000000}", Math.Pow (num, 1 / num)); 7 | } 8 | } -------------------------------------------------------------------------------- /C#/timeloop.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class timeloop { 4 | public static void Main (string[] args) { 5 | int num = int.Parse (Console.ReadLine ()); 6 | for (int x = 1; x <= num; x++) 7 | Console.WriteLine (x + " Abracadabra"); 8 | } 9 | } -------------------------------------------------------------------------------- /C#/tolower.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class tolower { 4 | public static void Main (string[] args) { 5 | string line = Console.ReadLine (); 6 | int space = line.IndexOf (' '); 7 | int problems = int.Parse (line.Substring (0, space)); 8 | int cases = int.Parse (line.Substring (space + 1)); 9 | int max = problems; 10 | for (int z = 0; z < problems; z++) { 11 | bool moreUpper = false; 12 | for (int x = 0; x < cases; x++) { 13 | string s = Console.ReadLine (); 14 | if (!moreUpper) { 15 | for (int a = 1; a < s.Length; a++) { 16 | if (char.IsUpper (s[a])) { 17 | moreUpper = true; 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | if (moreUpper) 24 | max--; 25 | } 26 | Console.WriteLine (max); 27 | } 28 | } -------------------------------------------------------------------------------- /C#/trik.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class trik { 4 | public static void Main (string[] args) { 5 | string sequence = Console.ReadLine (); 6 | int position = 1; 7 | for (int x = 0; x < sequence.Length; x++) { 8 | string letter = sequence[x] + ""; 9 | if (letter.Equals ("A")) { 10 | if (position == 1) 11 | position++; 12 | else if (position == 2) 13 | position--; 14 | } else if (letter.Equals ("B")) { 15 | if (position == 2) 16 | position++; 17 | else if (position == 3) 18 | position--; 19 | } else { 20 | if (position == 1) 21 | position += 2; 22 | else if (position == 3) 23 | position -= 2; 24 | } 25 | } 26 | Console.WriteLine (position); 27 | } 28 | } -------------------------------------------------------------------------------- /C#/trollhunt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class trollhunt { 5 | public static void Main (string[] args) { 6 | int[] nums = Console.ReadLine ().Split ().Select (s => int.Parse (s)).ToArray (); 7 | Console.WriteLine (Math.Ceiling ((nums[0] - 1) / (double) (nums[1] / nums[2]))); 8 | } 9 | } -------------------------------------------------------------------------------- /C#/zamka.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class zamka { 4 | public static void Main (string[] args) { 5 | int low = int.Parse (Console.ReadLine ()) - 1; 6 | int high = int.Parse (Console.ReadLine ()); 7 | int x = int.Parse (Console.ReadLine ()); 8 | int min = 0; 9 | int max = 0; 10 | while (low++ <= high) { 11 | char[] digits = low.ToString ().ToCharArray (); 12 | int sum = 0; 13 | foreach (char s in digits) 14 | sum += int.Parse (s + ""); 15 | if (sum == x) { 16 | if (min == 0) { 17 | min = low; 18 | max = low; 19 | } 20 | max = low; 21 | } 22 | } 23 | Console.WriteLine (min + "\n" + max); 24 | } 25 | } -------------------------------------------------------------------------------- /C#/zanzibar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class zanzibar { 4 | public static void Main (string[] args) { 5 | int cases = int.Parse (Console.ReadLine ()); 6 | while (cases-- > 0) { 7 | string[] nums = Console.ReadLine ().Split (' '); 8 | int notBorn = 0; 9 | for (int x = 0; x < nums.Length - 2; x++) { 10 | int yearLater = int.Parse (nums[x + 1]); 11 | int currentYear = int.Parse (nums[x]) * 2; 12 | if (yearLater > currentYear) 13 | notBorn += yearLater - currentYear; 14 | } 15 | Console.WriteLine (notBorn); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /C++/akcija.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool opposite(int a, int b) { 8 | return a > b; 9 | } 10 | 11 | int main() { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | int cases; 15 | cin >> cases; 16 | long total = 0; 17 | vector arr; 18 | while (cases-- > 0) { 19 | int num; 20 | cin >> num; 21 | arr.push_back(num); 22 | } 23 | sort(arr.begin(), arr.end(), opposite); 24 | for (int x = 0; x < arr.size(); x++) 25 | if (x % 3 != 2) 26 | total += arr[x]; 27 | cout << total; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/alphabetanimals.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | string s; 9 | int n; 10 | cin >> s >> n; 11 | string arr[n]; 12 | for (int x = 0; x < n; x++) 13 | cin >> arr[x]; 14 | auto solve = [&]() { 15 | char last = s[s.size() - 1]; 16 | int count['z' + 1] = {0}; 17 | vector v; 18 | for (int x = 0; x < n; x++) { 19 | string a = arr[x]; 20 | count[a[0]]++; 21 | if (a[0] == last) 22 | v.push_back(a); 23 | } 24 | if (v.empty()) { 25 | cout << '?'; 26 | return; 27 | } 28 | for (string a : v) { 29 | if (!count[a[a.size() - 1]] || 30 | a[0] == a[a.size() - 1] && count[a[0]] == 1) { 31 | cout << a << '!'; 32 | return; 33 | } 34 | } 35 | cout << v[0]; 36 | }; 37 | solve(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /C++/anewalphabet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | string arr[] = {"@", "8", "(", "|)", "3", "#", "6", 9 | "[-]", "|", "_|", "|<", "1", "[]\\/[]", "[]\\[]", 10 | "0", "|D", "(,)", "|Z", "$", "\'][\'", "|_|", 11 | "\\/", "\\/\\/", "}{", "`/", "2"}; 12 | string line; 13 | getline(cin, line); 14 | for (int x = 0; x < line.length(); x++) { 15 | int c = line[x]; 16 | if (isalpha(line[x])) { 17 | if (c >= 'A' && c <= 'Z') 18 | c += 32; 19 | cout << arr[c - 'a']; 20 | } else 21 | cout << line[x]; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/areal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | double a; 10 | cin >> a; 11 | printf("%.10lf", 4 * sqrt(a)); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C++/babybites.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | int bites; 9 | cin >> bites; 10 | cin.ignore(); 11 | string line; 12 | for (int x = 1; x <= bites; x++) { 13 | cin >> line; 14 | if (line == "mumble") 15 | continue; 16 | if (to_string(x) != line) { 17 | cout << "something is fishy"; 18 | return 0; 19 | } 20 | } 21 | cout << "makes sense"; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++/beatspread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | while (n-- > 0) { 11 | int a, b; 12 | cin >> a >> b; 13 | int pos1, pos2; 14 | pos1 = (a + b) / 2; 15 | pos2 = a - pos1; 16 | 17 | if (pos1 >= 0 && pos2 >= 0 && pos1 + pos2 == a && abs(pos1 - pos2) == b) 18 | cout << max(pos1, pos2) << ' ' << min(pos1, pos2) << '\n'; 19 | else 20 | cout << "impossible" << '\n'; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++/beavergnaw.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | 9 | const double pi = acos(-1); 10 | double diameter, vol; 11 | while (cin >> diameter >> vol) { 12 | if (diameter == 0 and vol == 0) 13 | return 0; 14 | double d = pow(((diameter * diameter * diameter) * pi - 6 * vol) / pi, 15 | 1 / 3.0); 16 | printf("%.9lf\n", d); 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | long nextPowOf(long a, long b) { 6 | return (long)(log(a) / log(b)); 7 | } 8 | 9 | int main() { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | int cases; 13 | cin >> cases; 14 | while (cases-- > 0) { 15 | long num, max = 0; 16 | cin >> num; 17 | long pow10 = (long)pow(10, nextPowOf(num, 10)); 18 | for (; pow10 > 0; pow10 /= 10) { 19 | long count = 0; 20 | for (long temp = num / pow10; temp > 0; count++) 21 | temp -= (long)pow(2, nextPowOf(temp, 2)); 22 | if (count > max) 23 | max = count; 24 | } 25 | cout << max << "\n"; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/brokenswords.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int cases, tb = 0, lr = 0; 9 | cin >> cases; 10 | while (cases-- > 0) { 11 | char c; 12 | for (int x = 0; x < 2; x++) { 13 | cin >> c; 14 | if (c == '0') 15 | tb++; 16 | } 17 | for (int x = 0; x < 2; x++) { 18 | cin >> c; 19 | if (c == '0') 20 | lr++; 21 | } 22 | } 23 | int swords = min(tb / 2, lr / 2); 24 | int dsword = swords * 2; 25 | cout << swords << ' ' << tb - dsword << ' ' << lr - dsword; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++/climbingworm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int a, b, h; 9 | cin >> a >> b >> h; 10 | int ans = max(0, (int)ceil(h / (double)(a - b)) - 5); 11 | int height = ans * (a - b); 12 | while (1) { 13 | height += a; 14 | ans++; 15 | if (height >= h) 16 | break; 17 | height -= b; 18 | } 19 | cout << ans; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/compass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int cur, goal; 9 | cin >> cur >> goal; 10 | int cw = cur > goal ? 360 - cur + goal : goal > cur ? goal - cur : 0; 11 | int ccw = cur > goal ? cur - goal : goal > cur ? 360 - goal + cur : 0; 12 | if (cw == 180) 13 | cout << 180; 14 | else 15 | cout << (cw < ccw ? cw : -ccw); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++/convexpolygonarea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef pair pi; 6 | 7 | int main() { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(0); 10 | int cases; 11 | cin >> cases; 12 | while (cases-- > 0) { 13 | int points; 14 | cin >> points; 15 | pi arr[points]; 16 | for (int x = 0; x < points; x++) 17 | cin >> arr[x].first >> arr[x].second; 18 | double sum = 0; 19 | for (int x = 0; x < points; x++) { 20 | sum += arr[x].first * arr[x + 1 == points ? 0 : x + 1].second; 21 | sum -= arr[x].second * arr[x + 1 == points ? 0 : x + 1].first; 22 | } 23 | cout << sum / 2 << '\n'; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++/cudoviste.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int r, c; 9 | cin >> r >> c; 10 | char map[r][c]; 11 | for (int a = 0; a < r; a++) 12 | for (int s = 0; s < c; s++) 13 | cin >> map[a][s]; 14 | int arr[5] = {0, 0, 0, 0, 0}; 15 | for (int row = 0; row < r - 1; row++) { 16 | for (int col = 0; col < c - 1; col++) { 17 | int num = 0; 18 | char tl = map[row][col], tr = map[row][col + 1]; 19 | char bl = map[row + 1][col], br = map[row + 1][col + 1]; 20 | if (tl == '#' || tr == '#' || bl == '#' || br == '#') 21 | continue; 22 | if (tl == 'X') 23 | num++; 24 | if (tr == 'X') 25 | num++; 26 | if (bl == 'X') 27 | num++; 28 | if (br == 'X') 29 | num++; 30 | arr[num]++; 31 | } 32 | } 33 | cout << arr[0] << "\n" 34 | << arr[1] << "\n" 35 | << arr[2] << "\n" 36 | << arr[3] << "\n" 37 | << arr[4]; 38 | return 0; 39 | } -------------------------------------------------------------------------------- /C++/dasblinkenlights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } 6 | 7 | int lcm(int a, int b) { return a * b / gcd(a, b); } 8 | 9 | int main() { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(nullptr); 12 | int first, second, max; 13 | cin >> first >> second >> max; 14 | cout << (lcm(first, second) <= max ? "yes" : "no"); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++/dicegame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int g[4]; 9 | int e[4]; 10 | cin >> g[0] >> g[1] >> g[2] >> g[3]; 11 | cin >> e[0] >> e[1] >> e[2] >> e[3]; 12 | int sum1 = g[0] + g[1] + g[2] + g[3]; 13 | int sum2 = e[0] + e[1] + e[2] + e[3]; 14 | cout << (sum1 > sum2 ? "Gunnar" : (sum2 > sum1 ? "Emma" : "Tie")); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++/egypt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int a, b, c; 9 | while (cin >> a >> b >> c) { 10 | if (a == b && b == c && a == 0) 11 | break; 12 | int big = max(a, max(b, c)); 13 | if (a == big) 14 | swap(a, c); 15 | else if (b == big) 16 | swap(b, c); 17 | cout << (a * a + b * b == c * c ? "right" : "wrong") << '\n'; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/erraticants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, s; 9 | cin >> n; 10 | while (n-- > 0) { 11 | cin >> s; 12 | int arr[2 * s + 1][2 * s + 1]; 13 | memset(arr, 10000, sizeof arr); 14 | int step = 1, r = s, c = s; 15 | arr[r][c] = 1; 16 | while (s-- > 0) { 17 | int pr = r, pc = c; 18 | char a; 19 | cin >> a; 20 | if (a == 'N') 21 | r--; 22 | else if (a == 'S') 23 | r++; 24 | else if (a == 'W') 25 | c--; 26 | else 27 | c++; 28 | arr[pr][pc] = min(arr[pr][pc], arr[r][c] + 1); 29 | arr[r][c] = step = min(arr[r][c], ++step); 30 | } 31 | cout << step - 1 << '\n'; 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++/fallingapart.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | int arr[n]; 11 | for (int x = 0; x < n; x++) 12 | cin >> arr[x]; 13 | sort(arr, arr + n, greater()); 14 | int a = 0, b = 0; 15 | for (int x = 0; x < n; x++) 16 | if ((x & 1) == 0) 17 | a += arr[x]; 18 | else 19 | b += arr[x]; 20 | cout << a << ' ' << b; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/fiftyshades.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, c; 9 | string s; 10 | cin >> n; 11 | while (n--) { 12 | cin >> s; 13 | transform(s.begin(), s.end(), s.begin(), ::tolower); 14 | if (s.find("pink") != string::npos || s.find("rose") != string::npos) 15 | c++; 16 | } 17 | if (c == 0) 18 | cout << "I must watch Star Wars with my daughter"; 19 | else 20 | cout << c; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/freefood.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | bool food[366]; 9 | memset(food, 0, sizeof(food)); 10 | int cases; 11 | cin >> cases; 12 | int mmin = 400, mmax = -1; 13 | while (cases-- > 0) { 14 | int a, b; 15 | cin >> a >> b; 16 | mmin = min(mmin, a); 17 | mmax = max(mmax, b); 18 | for (; a <= b; a++) 19 | food[a] = true; 20 | } 21 | int days = 0; 22 | for (; mmin <= mmax; mmin++) 23 | if (food[mmin]) 24 | days++; 25 | cout << days; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++/fundamentalneighbors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n; 9 | while (cin >> n) { 10 | cout << n << ' '; 11 | int neighbor = 1; 12 | int c = 0; 13 | if ((n & 1) == 0) { 14 | while ((n & 1) == 0) { 15 | n >>= 1; 16 | c++; 17 | } 18 | neighbor *= (int)pow(c, 2); 19 | } 20 | for (int x = 3; x < sqrt(n) + 1; x += 2) { 21 | c = 0; 22 | while (n % x == 0) { 23 | n /= x; 24 | c++; 25 | } 26 | if (c > 0) 27 | neighbor *= (int)pow(c, x); 28 | } 29 | cout << neighbor << '\n'; 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++/goatrope.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int x, y; 6 | 7 | double dist(int x1, int y1) { 8 | int xd = x - x1; 9 | int yd = y - y1; 10 | return sqrt(xd * xd + yd * yd); 11 | } 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(0); 16 | int x1, y1, x2, y2; 17 | cin >> x >> y >> x1 >> y1 >> x2 >> y2; 18 | double d; 19 | if (x >= x1 && x <= x2) 20 | d = y < y1 ? y1 - y : y - y2; 21 | else if (y >= y1 && y <= y2) 22 | d = x < x1 ? x1 - x : x - x2; 23 | else if (x < x1) 24 | d = dist(x1, y < y1 ? y1 : y2); 25 | else 26 | d = dist(x2, y < y1 ? y1 : y2); 27 | cout << d; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/greedilyincreasing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, max = -1, count = 0; 9 | string s = ""; 10 | cin >> n; 11 | while (n-- > 0) { 12 | int a; 13 | cin >> a; 14 | if (a > max) { 15 | max = a; 16 | s += to_string(a) + " "; 17 | count++; 18 | } 19 | } 20 | cout << count << '\n' << s; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/harshadnumbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int sumDig(int n) { 6 | int sum = 0; 7 | while (n > 0) { 8 | sum += n % 10; 9 | n /= 10; 10 | } 11 | return sum; 12 | } 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); 16 | cin.tie(0); 17 | int n; 18 | cin >> n; 19 | while (n % sumDig(n) != 0) 20 | n++; 21 | cout << n << "\n"; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++/heartrate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int cases; 7 | scanf("%d", &cases); 8 | while (cases-- > 0) { 9 | double beats, seconds; 10 | scanf("%lf %lf", &beats, &seconds); 11 | double unacc = (60 * beats) / seconds, 12 | acc = 60 / seconds; 13 | printf("%lf %lf %lf\n", unacc - acc, unacc, unacc + acc); 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++/heirsdilemma.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool pass(int n) { 6 | int sub = n; 7 | int arr[10]; 8 | memset(arr, 0, sizeof(arr)); 9 | while (sub > 0) { 10 | int dig = sub % 10; 11 | if (dig == 0) 12 | return false; 13 | if (arr[dig] > 0) 14 | return false; 15 | if (n % dig != 0) 16 | return false; 17 | arr[dig]++; 18 | sub /= 10; 19 | } 20 | return true; 21 | } 22 | 23 | int main() { 24 | ios_base::sync_with_stdio(false); 25 | cin.tie(0); 26 | int lb, ub, count = 0; 27 | cin >> lb >> ub; 28 | for (int x = lb; x <= ub; x++) 29 | if (pass(x)) 30 | count++; 31 | cout << count; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++/hindex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | int arr[n]; 11 | int low = 0, high = (int)1e10, ans; 12 | for (int x = 0; x < n; x++) 13 | cin >> arr[x]; 14 | while (low < high) { 15 | int mid = (low + high) / 2; 16 | int count = 0; 17 | for (int x : arr) 18 | if (x >= mid) 19 | count++; 20 | if (count < mid) 21 | high = mid; 22 | else { 23 | ans = mid; 24 | low = mid + 1; 25 | } 26 | } 27 | cout << ans; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/howl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | string s; 9 | cin >> s; 10 | cout << s << 'O'; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++/howmanydigits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | double arr[1000001]; 9 | arr[0] = 0; 10 | for (int x = 1; x <= 1000000; x++) 11 | arr[x] = arr[x - 1] + log10(x); 12 | int num; 13 | while (cin >> num) 14 | cout << (int)arr[num] + 1 << '\n'; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++/humancannonball2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | 9 | int cases; 10 | double vel, angle, deltaX, h1, h2, toRadians = acos(-1) / 180; 11 | cin >> cases; 12 | while (cases-- > 0) { 13 | cin >> vel >> angle >> deltaX >> h1 >> h2; 14 | double time = deltaX / vel / cos(angle * toRadians); 15 | double deltaY = 16 | vel * time * sin(angle * toRadians) - .5 * 9.81 * time * time; 17 | cout << (deltaY >= h1 + 1 and deltaY <= h2 - 1 ? "Safe\n" 18 | : "Not Safe\n"); 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/krizaljka.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | string a, b; 9 | cin >> a >> b; 10 | int row = -1, col = -1; 11 | for (int c = 0; c < a.length(); c++) { 12 | for (int r = 0; r < b.length(); r++) { 13 | if (b[r] == a[c]) { 14 | row = r; 15 | col = c; 16 | break; 17 | } 18 | } 19 | if (row != -1 && col != -1) 20 | break; 21 | } 22 | for (int r = 0; r < b.length(); r++) { 23 | for (int c = 0; c < a.length(); c++) { 24 | if (c == col) 25 | cout << b[r]; 26 | else if (r == row) 27 | cout << a[c]; 28 | else 29 | cout << '.'; 30 | } 31 | cout << '\n'; 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++/leftbeehind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | for (int sweet, sour; cin >> sweet >> sour;) { 9 | if (sweet == 0 && sour == 0) 10 | break; 11 | if (sour + sweet == 13) 12 | cout << "Never speak again." 13 | << "\n"; 14 | else if (sour > sweet) 15 | cout << "Left beehind." 16 | << "\n"; 17 | else if (sweet > sour) 18 | cout << "To the convention." 19 | << "\n"; 20 | else 21 | cout << "Undecided." 22 | << "\n"; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++/licensetolaunch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | int d = 0, val; 11 | cin >> val; 12 | for (int x = 1, a; x < n; x++) { 13 | cin >> a; 14 | if (a < val) { 15 | d = x; 16 | val = a; 17 | } 18 | } 19 | cout << d; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/limbo1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef unsigned long long ull; 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(nullptr); 10 | ull cases, left, right; 11 | cin >> cases; 12 | while (cases-- > 0) { 13 | cin >> left >> right; 14 | // use gauss formula 15 | // 1 + (left * (left + 1)) / 2 16 | // (right * (left + left + right + 3)) / 2 17 | ull val1 = 1 + (left * (left + 1)) / 2; 18 | ull val2 = (right * (left + left + right + 3)) / 2; 19 | cout << val1 + val2 << "\n"; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/loworderzeros.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | int arr[1000001]; 8 | long a = 1; 9 | for (int x = 1; x <= 1000000; x++) { 10 | a *= x; 11 | while (a % 10 == 0) 12 | a /= 10; 13 | arr[x] = a % 10; 14 | a %= 10000000; 15 | } 16 | for (;;) { 17 | int num; 18 | cin >> num; 19 | if (num == 0) 20 | break; 21 | cout << arr[num] << "\n"; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/luhnchecksum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(nullptr); 8 | int cases; 9 | cin >> cases; 10 | while (cases-- > 0) { 11 | string line; 12 | cin >> line; 13 | int sum = 0; 14 | for (int x = line.size() - 1, a = 1; x >= 0; x--, a++) { 15 | int dig = line[x] - '0'; 16 | if ((a & 1) == 0) { 17 | dig <<= 1; 18 | if (dig > 9) 19 | dig = dig % 10 + dig / 10 % 10; 20 | } 21 | sum += dig; 22 | } 23 | cout << (sum % 10 == 0 ? "PASS" : "FAIL") << "\n"; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++/marko.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int arr[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 9 | 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9}; 10 | int n; 11 | cin >> n; 12 | string words[n]; 13 | for (int x = 0; x < n; x++) 14 | cin >> words[x]; 15 | string key; 16 | cin >> key; 17 | int count = 0; 18 | for (int x = 0; x < n; x++) { 19 | if (words[x].length() != key.length()) 20 | continue; 21 | string word = words[x]; 22 | bool valid = true; 23 | for (int a = 0; a < key.length(); a++) 24 | if (arr[word[a] - 'a'] != key[a] - '0') { 25 | valid = false; 26 | break; 27 | } 28 | if (valid) 29 | count++; 30 | } 31 | cout << count; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++/mathhomework.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int legs[3]; 9 | int total, count = 0; 10 | cin >> legs[0] >> legs[1] >> legs[2] >> total; 11 | for (int a = 0; a <= total / legs[0]; a++) 12 | for (int b = 0; b <= total / legs[1]; b++) 13 | for (int c = 0; c <= total / legs[2]; c++) 14 | if (a * legs[0] + b * legs[1] + c * legs[2] == total) { 15 | cout << a << " " << b << " " << c << "\n"; 16 | count++; 17 | } 18 | if (count == 0) 19 | cout << "impossible\n"; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++/nsum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, sum = 0; 9 | cin >> n; 10 | while (n--) { 11 | int v; 12 | cin >> v; 13 | sum += v; 14 | } 15 | cout << sum; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++/pascal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int N; 6 | 7 | int main() { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(0); 10 | cin >> N; 11 | if (N == 1) 12 | cout << 0; 13 | else if (!(N & 1)) 14 | cout << N - (N >> 1); 15 | else { 16 | bool isprime = 1; 17 | for (int x = 3; x <= sqrt(N); x += 2) 18 | if (!(N % x)) { 19 | cout << N - (N / x); 20 | isprime = 0; 21 | break; 22 | } 23 | if (isprime) 24 | cout << N - 1; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++/patuljci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int g[9]; 9 | int idx[100]; 10 | memset(idx, -1, sizeof(idx)); 11 | for (int x = 0; x < 9; x++) { 12 | cin >> g[x]; 13 | idx[g[x]] = x; 14 | } 15 | sort(g, g + 9); 16 | int sum = g[0] + g[1] + g[2] + g[3] + g[4] + g[5] + g[6]; 17 | while (sum != 100) { 18 | next_permutation(g, g + 9); 19 | sum = g[0] + g[1] + g[2] + g[3] + g[4] + g[5] + g[6]; 20 | } 21 | for (int a = 0; a < 7; a++) { 22 | int gIndex = 0; 23 | for (int x = 0, min = 10; x < 7; x++) 24 | if (idx[g[x]] < min) { 25 | min = idx[g[x]]; 26 | gIndex = x; 27 | } 28 | idx[g[gIndex]] = 10; 29 | cout << g[gIndex] << "\n"; 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++/pauleigon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | int swap, pscore, oppscore; 8 | cin >> swap >> pscore >> oppscore; 9 | int current = (pscore + oppscore) / swap; 10 | cout << ((current & 1) == 1 ? "opponent" : "paul"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++/primaryarithmetic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long LL; 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(0); 10 | LL a, b; 11 | while (cin >> a >> b) { 12 | if (!a && !b) 13 | break; 14 | int count = 0, carry = 0; 15 | while (a || b) { 16 | int d1 = a % 10, d2 = b % 10; 17 | int sum = d1 + d2 + carry; 18 | if (sum > 9) { 19 | count++; 20 | carry = 1; 21 | } else { 22 | carry = 0; 23 | } 24 | a /= 10; 25 | b /= 10; 26 | } 27 | cout << (count ? to_string(count) + " " : "No ") + "carry operation" + (count > 1 ? "s" : "") + "." << '\n'; 28 | } 29 | } -------------------------------------------------------------------------------- /C++/princesspeach.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int n, y; 9 | cin >> n >> y; 10 | bool arr[n]; 11 | int count = 0; 12 | memset(arr, 1, sizeof arr); 13 | while (y-- > 0) { 14 | int a; 15 | cin >> a; 16 | if (arr[a]) { 17 | count++; 18 | arr[a] = false; 19 | } 20 | } 21 | for (int x = 0; x < n; x++) 22 | if (arr[x]) 23 | cout << x << '\n'; 24 | cout << "Mario got " << count << " of the dangerous obstacles."; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++/provincesandgold.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int vic[][2] = {{8, 6}, {5, 3}, {2, 1}}; 9 | int tre[][2] = {{6, 3}, {3, 2}, {0, 1}}; 10 | int g, s, c, val; 11 | cin >> g >> s >> c; 12 | val = g * tre[0][1] + s * tre[1][1] + c * tre[2][1]; 13 | string tcard = 14 | val >= tre[0][0] ? "Gold" : (val >= tre[1][0] ? "Silver" : "Copper"); 15 | string vcard = 16 | val >= vic[0][0] 17 | ? "Province" 18 | : (val >= vic[1][0] ? "Duchy" : (val >= vic[2][0] ? "Estate" : "")); 19 | if (vcard.length() == 0) 20 | cout << tcard; 21 | else 22 | cout << vcard << " or " << tcard; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++/prsteni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int gcm(int a, int b) { 6 | return b == 0 ? a : gcm(b, a % b); 7 | } 8 | 9 | int main() { 10 | ios_base::sync_with_stdio(false); 11 | int cases, first; 12 | cin >> cases >> first; 13 | while (cases-- > 1) { 14 | int num; 15 | cin >> num; 16 | int div = gcm(first, num); 17 | cout << first / div << "/" << num / div << "\n"; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/relocation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int companies, queries; 9 | cin >> companies >> queries; 10 | int arr[companies]; 11 | for (int x = 0; x < companies; x++) 12 | cin >> arr[x]; 13 | while (queries-- > 0) { 14 | int type, a, b; 15 | cin >> type >> a >> b; 16 | if (type == 1) 17 | arr[a - 1] = b; 18 | else 19 | cout << abs(arr[a - 1] - arr[b - 1]) << "\n"; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/sodaslurper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int bottles(int has, int needs, int count, int extra) { 6 | if (has == 0) 7 | return count; 8 | int a = (has + extra) / needs; 9 | return bottles(a, needs, a + count, (has + extra) % needs); 10 | } 11 | 12 | int main() { 13 | ios_base::sync_with_stdio(false); 14 | int start, found, require; 15 | cin >> start >> found >> require; 16 | cout << bottles(start + found, require, 0, 0); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C++/sok.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | double a, b, c, i, j, k; 9 | cin >> a >> b >> c >> i >> j >> k; 10 | double m = min(a / i, min(b / j, c / k)); 11 | double val = m * i; 12 | a -= val; 13 | b -= val = m * j; 14 | c -= val = m * k; 15 | cout << setprecision(6) << fixed; 16 | cout << a << " " << b << " " << c; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C++/statistics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int nums; 9 | for (int a = 1; cin >> nums; a++) { 10 | int min = 1000001, max = -1000001; 11 | for (int x = 0; x < nums; x++) { 12 | int num; 13 | cin >> num; 14 | if (num < min) 15 | min = num; 16 | if (num > max) 17 | max = num; 18 | } 19 | cout << "Case " << a << ": " << min << " " << max << " " << max - min << "\n"; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++/thelastproblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | string s; 9 | getline(cin, s); 10 | cout << "Thank you, " << s << ", and farewell!"; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++/veci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int a; 9 | cin >> a; 10 | int num = a; 11 | int digs = (int)log10(a) + 1; 12 | int arr[digs]; 13 | for (int x = 0; x < digs; x++) { 14 | arr[x] = a % 10; 15 | a /= 10; 16 | } 17 | sort(arr, arr + digs); 18 | int MIN = 1000000; 19 | do { 20 | int s = 0; 21 | for (int x = digs - 1; x >= 0; x--) 22 | s = s * 10 + arr[x]; 23 | if (s > num && s < MIN) 24 | MIN = s; 25 | } while (next_permutation(arr, arr + digs)); 26 | cout << (MIN == 1000000 ? 0 : MIN); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/volim.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | int p, ques, time = 0; 9 | cin >> p >> ques; 10 | while (ques-- > 0) { 11 | int t; 12 | char c; 13 | cin >> t >> c; 14 | time += t; 15 | if (time > 210) 16 | break; 17 | if (c == 'T') 18 | p = p == 8 ? 1 : p + 1; 19 | } 20 | cout << p; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C/electricaloutlets.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | scanf("%d", &n); 6 | while (n--) { 7 | int k; 8 | scanf("%d", &k); 9 | int ans = -k + 1; 10 | while (k--) { 11 | int o; 12 | scanf("%d", &o); 13 | ans += o; 14 | } 15 | printf("%d\n", ans); 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C/finalexam2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int n; 6 | char a[10], b[10]; 7 | scanf("%d %s", &n, a); 8 | int ans = 0; 9 | for (int i = 0; i < n - 1; i++) { 10 | scanf("%s", b); 11 | if (strcmp(a, b) == 0) ans++; 12 | memcpy(a, b, sizeof(char) * 10); 13 | } 14 | printf("%d", ans); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C/greetings2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char s[2000]; 6 | scanf("%s", s); 7 | int ecount = 0; 8 | int len = strlen(s); 9 | for (int i = 0; i < len; i++) { 10 | char c = s[i]; 11 | if (c == 'e') ecount++; 12 | } 13 | printf("h"); 14 | for (int i = 0; i < ecount * 2; i++) { 15 | printf("e"); 16 | } 17 | printf("y"); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C/heimavinna.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool is_num(char c) { return c >= '0' && c <= '9'; } 5 | 6 | char read_num(int *a) { 7 | int cur = 0; 8 | while (1) { 9 | char c; 10 | scanf("%c", &c); 11 | if (is_num(c)) { 12 | cur = cur * 10 + c - '0'; 13 | } else { 14 | *a = cur; 15 | return c; 16 | } 17 | } 18 | } 19 | 20 | int main() { 21 | int ans = 0; 22 | while (1) { 23 | int a, b; 24 | char sep = read_num(&a); 25 | if (sep == '-') { 26 | read_num(&b); 27 | ans += b - a + 1; 28 | } else if (a != 0) { 29 | ans++; 30 | } else { 31 | break; 32 | } 33 | } 34 | printf("%d", ans); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C/ofugsnuid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | scanf("%d", &n); 6 | int nums[n]; 7 | for (int i = 0; i < n; i++) { 8 | scanf("%d", &nums[i]); 9 | } 10 | for (int i = n - 1; i >= 0; i--) { 11 | printf("%d\n", nums[i]); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C/savingforretirement.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int b, br, bs, a, as; 5 | scanf("%d %d %d %d %d", &b, &br, &bs, &a, &as); 6 | int bobmoney = (br - b) * bs; 7 | int years = (int)(1.0 * bobmoney / as) + 1; 8 | printf("%d", a + years); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C/sifferprodukt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x; 5 | scanf("%d", &x); 6 | while (x >= 10) { 7 | int temp = x; 8 | int mul = 1; 9 | while (temp) { 10 | int d = temp % 10; 11 | temp /= 10; 12 | if (d) mul *= d; 13 | } 14 | x = mul; 15 | } 16 | printf("%d", x); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C/tornbygge.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | scanf("%d", &n); 6 | int prev, cur; 7 | scanf("%d", &prev); 8 | int ans = 1; 9 | for (int i = 0; i < n - 1; i++) { 10 | scanf("%d", &cur); 11 | if (cur > prev) ans++; 12 | prev = cur; 13 | } 14 | printf("%d", ans); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Java/aaah.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/aaah 3 | import java.util.Scanner; 4 | 5 | public class aaah { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String say = sc.nextLine(); 10 | String hear = sc.nextLine(); 11 | System.out.println(say.compareTo(hear) > 0 ? "no" : "go"); 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/abc.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/abc 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.Scanner; 6 | 7 | public class abc { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int[] nums = new int[3]; 12 | for (int x = 0; x < 3; x++) 13 | nums[x] = sc.nextInt(); 14 | sc.nextLine(); 15 | Arrays.sort(nums); 16 | HashMap pairup = new HashMap<>(); 17 | for (int x = 0; x < 3; x++) 18 | pairup.put((char) ('A' + x), nums[x]); 19 | for (char c : sc.nextLine().toCharArray()) 20 | System.out.print(pairup.get(c) + " "); 21 | sc.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/aboveaverage.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/aboveaverage 3 | import java.util.Scanner; 4 | 5 | public class aboveaverage { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | double students = sc.nextDouble(); 12 | int[] grades = new int[(int) students]; 13 | double average = 0; 14 | for (int x = 0; x < students; x++) { 15 | grades[x] = sc.nextInt(); 16 | average += grades[x]; 17 | } 18 | average /= students; 19 | double count = 0; 20 | for (int s : grades) 21 | if (s > average) 22 | count++; 23 | System.out.printf("%.3f%s", (count / students) * 100, "%\n"); 24 | } 25 | sc.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Java/alphabetspam.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/alphabetspam 3 | import java.util.Scanner; 4 | 5 | public class alphabetspam { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String line = sc.nextLine(); 10 | double length = line.length(); 11 | double whitespace = 0; 12 | double lowercase = 0; 13 | double uppercase = 0; 14 | double symbols = 0; 15 | for (int x = 0; x < line.length(); x++) { 16 | if (line.charAt(x) == '_') 17 | whitespace++; 18 | else if ((int) line.charAt(x) >= 97 && (int) line.charAt(x) <= 122) 19 | lowercase++; 20 | else if ((int) line.charAt(x) >= 65 && (int) line.charAt(x) <= 90) 21 | uppercase++; 22 | else 23 | symbols++; 24 | } 25 | System.out.printf("%.16f\n", whitespace / length); 26 | System.out.printf("%.16f\n", lowercase / length); 27 | System.out.printf("%.16f\n", uppercase / length); 28 | System.out.printf("%.16f\n", symbols / length); 29 | sc.close(); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/anothercandies.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/anothercandies 3 | import java.math.BigInteger; 4 | import java.util.Scanner; 5 | 6 | public class anothercandies { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | while (cases-- > 0) { 12 | sc.nextLine(); 13 | long children = sc.nextLong(); 14 | BigInteger total = BigInteger.ZERO; 15 | for (long x = 0; x < children; x++) 16 | total = total.add(BigInteger.valueOf(sc.nextLong())); 17 | System.out.println(BigInteger.ZERO.equals(total.mod(BigInteger.valueOf(children))) ? "YES" : "NO"); 18 | } 19 | 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/apaxiaaans.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/apaxiaaans 3 | import java.util.Scanner; 4 | 5 | public class apaxiaaans { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String name = sc.nextLine(); 10 | String compact = ""; 11 | if (name.length() == 1) 12 | compact = name; 13 | else { 14 | for (int x = 0; x < name.length() - 1; x++) 15 | if (name.charAt(x) != name.charAt(x + 1)) 16 | compact += name.charAt(x); 17 | compact += name.charAt(name.length() - 1); 18 | } 19 | System.out.println(compact); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/apaxianparent.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class apaxianparent { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String y = sc.next(); 8 | String p = sc.next(); 9 | if (y.matches(".*[aioue]$")) 10 | System.out.println(y.substring(0, y.length() - 1) + "ex" + p); 11 | else if (y.endsWith("ex")) 12 | System.out.println(y + p); 13 | else 14 | System.out.println(y + "ex" + p); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/apples.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class apples { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int R = sc.nextInt(); 8 | int C = sc.nextInt(); 9 | char[][] arr = new char[R][C]; 10 | for (int r = 0; r < R; r++) 11 | arr[r] = sc.next().toCharArray(); 12 | for (int c = 0; c < C; c++) { 13 | int available = 0; 14 | for (int r = R - 1; r >= 0; r--) { 15 | if (arr[r][c] == '.') 16 | available++; 17 | else if (arr[r][c] == '#') 18 | available = 0; 19 | else if (available > 0) { 20 | arr[r][c] = '.'; 21 | arr[r + available][c] = 'a'; 22 | } 23 | } 24 | } 25 | StringBuilder ans = new StringBuilder(); 26 | for (char[] r : arr) { 27 | for (char c : r) 28 | ans.append(c); 29 | ans.append('\n'); 30 | } 31 | System.out.println(ans); 32 | } 33 | } -------------------------------------------------------------------------------- /Java/artichoke.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class artichoke { 5 | static int p, a, b, c, d, n; 6 | 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc = new Scanner(System.in); 9 | p = sc.nextInt(); 10 | a = sc.nextInt(); 11 | b = sc.nextInt(); 12 | c = sc.nextInt(); 13 | d = sc.nextInt(); 14 | n = sc.nextInt(); 15 | double min = Integer.MAX_VALUE; 16 | double max = Integer.MIN_VALUE; 17 | double dist = 0; 18 | for (int x = 1; x <= n; x++) { 19 | double cur = price(x); 20 | if (cur > max) { 21 | dist = Math.max(dist, max - min); 22 | max = cur; 23 | min = max; 24 | } else { 25 | min = Math.min(min, cur); 26 | } 27 | } 28 | dist = Math.max(dist, max - min); 29 | System.out.println(dist); 30 | } 31 | 32 | static double price(int k) { 33 | return p * (Math.sin(a * k + b) + Math.cos(c * k + d) + 2); 34 | } 35 | } -------------------------------------------------------------------------------- /Java/astro.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class astro { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | sc.useDelimiter("\\s+|:"); 8 | boolean[] arr = new boolean[(int) 1e7]; 9 | String[] dow = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; 10 | int f = sc.nextInt() * 60 + sc.nextInt(); 11 | int s = sc.nextInt() * 60 + sc.nextInt(); 12 | int frate = sc.nextInt() * 60 + sc.nextInt(); 13 | int srate = sc.nextInt() * 60 + sc.nextInt(); 14 | for (int x = f; x < arr.length; x += frate) 15 | arr[x] = true; 16 | for (int x = s; x < arr.length; x += srate) 17 | if (arr[x]) { 18 | int day = x / 24 / 60 % 7; 19 | System.out.println(dow[day]); 20 | System.out.printf("%02d:%02d", x / 60 % 24, x % 60); 21 | return; 22 | } 23 | System.out.println("Never"); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/autori.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/autori 3 | import java.util.Scanner; 4 | 5 | public class autori { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String name = sc.nextLine(); 10 | String result = name.substring(0, 1); 11 | for (int x = 0; x < name.length(); x++) 12 | if (name.charAt(x) == '-') 13 | result += name.charAt(x + 1); 14 | System.out.println(result); 15 | sc.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/avion.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class avion { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int x = 1; 8 | int count = 0; 9 | while (sc.hasNext()) { 10 | if (sc.next().contains("FBI")) { 11 | System.out.print(x + " "); 12 | count++; 13 | } 14 | x++; 15 | } 16 | if (count == 0) 17 | System.out.println("HE GOT AWAY!"); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/babelfish.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class babelfish { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | HashMap dict = new HashMap<>(); 10 | String line; 11 | while ((line = sc.readLine()).contains(" ")) { 12 | String[] arr = line.split(" "); 13 | dict.put(arr[1], arr[0]); 14 | } 15 | 16 | while ((line = sc.readLine()) != null) 17 | dc.write(dict.containsKey(line) ? dict.get(line) + "\n" : "eh\n"); 18 | 19 | dc.close(); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/babylonian.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class babylonian { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int cases = Integer.parseInt(sc.readLine()); 10 | while (cases-- > 0) { 11 | String[] arr = (sc.readLine() + " ").split(","); 12 | long num = 0; 13 | for (int x = arr.length - 1; x >= 0; x--) { 14 | arr[x] = arr[x].trim(); 15 | if (!arr[x].equals("")) 16 | num += (long) Math.pow(60, arr.length - 1 - x) * Integer.parseInt(arr[x]); 17 | } 18 | dc.write(num + "\n"); 19 | } 20 | 21 | dc.close(); 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/backspace.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.OutputStreamWriter; 6 | 7 | public class backspace { 8 | public static void main(String[] args) throws IOException { 9 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 10 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 11 | 12 | char[] arr = sc.readLine().toCharArray(); 13 | for (int x = arr.length - 1, count = 0; x >= 0; x--) { 14 | if (arr[x] == '<') { 15 | arr[x] = ' '; 16 | count++; 17 | } else if (count > 0) { 18 | arr[x] = ' '; 19 | count--; 20 | } 21 | } 22 | dc.write(new String(arr).replaceAll(" ", "")); 23 | 24 | dc.flush(); 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/baconeggsandspam.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class baconeggsandspam { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | for (;;) { 8 | int n = sc.nextInt(); 9 | if (n == 0) 10 | break; 11 | TreeMap> map = new TreeMap<>(); 12 | for (int x = 0; x < n; x++) { 13 | String name = sc.next(); 14 | String[] list = sc.nextLine().trim().split(" "); 15 | for (String s : list) { 16 | TreeSet set = map.get(s); 17 | if (set == null) 18 | map.put(s, set = new TreeSet<>()); 19 | set.add(name); 20 | } 21 | } 22 | for (String key : map.keySet()) { 23 | System.out.print(key + " "); 24 | for (String val : map.get(key)) 25 | System.out.print(val + " "); 26 | System.out.println(); 27 | } 28 | System.out.println(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Java/basketballoneonone.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class basketballoneonone { 5 | public static void main(String args[]) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.next(); 8 | System.out.println(s.charAt(s.length() - 2)); 9 | } 10 | } -------------------------------------------------------------------------------- /Java/batterup.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/batterup 3 | import java.util.Scanner; 4 | 5 | public class batterup { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | double validCounts = 0; 11 | double total = 0; 12 | while (cases-- > 0) { 13 | int score = sc.nextInt(); 14 | if (score != -1) { 15 | validCounts++; 16 | total += score; 17 | } 18 | } 19 | System.out.println(total / validCounts); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/bela.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/bela 3 | import java.util.Scanner; 4 | 5 | public class bela { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt() * 4; 10 | String dominantSuit = sc.next(); 11 | int points = 0; 12 | sc.nextLine(); 13 | while (cases-- > 0) { 14 | String card = sc.nextLine(); 15 | if (card.contains("A")) 16 | points += 11; 17 | else if (card.contains("K")) 18 | points += 4; 19 | else if (card.contains("Q")) 20 | points += 3; 21 | else if (card.contains("T")) 22 | points += 10; 23 | else if (card.contains("9" + dominantSuit)) 24 | points += 14; 25 | else if (card.contains("J")) { 26 | if (card.contains(dominantSuit)) 27 | points += 20; 28 | else 29 | points += 2; 30 | } 31 | 32 | } 33 | System.out.println(points); 34 | sc.close(); 35 | } 36 | } -------------------------------------------------------------------------------- /Java/bijele.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/bijele 3 | import java.util.Scanner; 4 | 5 | public class bijele { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int correct[] = { 1, 1, 2, 2, 2, 8 }; 10 | 11 | for (int x : correct) 12 | System.out.print(x - sc.nextInt() + " "); 13 | sc.close(); 14 | } 15 | } -------------------------------------------------------------------------------- /Java/bookingaroom.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class bookingaroom { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String[] arr = sc.readLine().split(" "); 10 | boolean[] rooms = new boolean[Integer.parseInt(arr[0]) + 1]; 11 | int booked = Integer.parseInt(arr[1]); 12 | while (booked-- > 0) 13 | rooms[Integer.parseInt(sc.readLine())] = true; 14 | boolean found = false; 15 | for (int x = 1; x < rooms.length; x++) 16 | if (!rooms[x]) { 17 | dc.write(x + "\n"); 18 | found = true; 19 | break; 20 | } 21 | if (!found) 22 | dc.write("too late\n"); 23 | dc.close(); 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/bus.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/bus 3 | 4 | import java.io.BufferedReader; 5 | import java.io.BufferedWriter; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.io.OutputStreamWriter; 9 | 10 | public class bus { 11 | public static void main(String[] args) throws IOException { 12 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 13 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 14 | 15 | int cases = Integer.parseInt(sc.readLine()); 16 | while (cases-- > 0) { 17 | int times = Integer.parseInt(sc.readLine()); 18 | double sum = 0; 19 | for (int x = 0; x < times; x++) 20 | sum = 2 * (sum + .5); 21 | dc.write((int) sum + "\n"); 22 | } 23 | 24 | dc.flush(); 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/carrots.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/carrots 3 | import java.util.Scanner; 4 | 5 | public class carrots { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int contestants = sc.nextInt(); 10 | int solved = sc.nextInt(); 11 | 12 | String name; 13 | while (contestants-- > 0) 14 | name = sc.nextLine(); 15 | 16 | System.out.println(solved); 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/cetvrta.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/cetvrta 3 | import java.util.Scanner; 4 | 5 | public class cetvrta { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int[] x = new int[3]; 10 | int[] y = new int[3]; 11 | for (int z = 0; z < 3; z++) { 12 | x[z] = sc.nextInt(); 13 | y[z] = sc.nextInt(); 14 | } 15 | 16 | for (int s : x) { 17 | int count = 0; 18 | for (int a : x) 19 | if (s == a) 20 | count++; 21 | if (count == 1) 22 | System.out.print(s + " "); 23 | } 24 | 25 | for (int s : y) { 26 | int count = 0; 27 | for (int a : y) 28 | if (s == a) 29 | count++; 30 | if (count == 1) 31 | System.out.print(s); 32 | } 33 | sc.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Java/chanukah.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class chanukah { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int cases = Integer.parseInt(sc.readLine()); 10 | while (cases-- > 0) { 11 | String[] tokens = sc.readLine().split(" "); 12 | int n = Integer.parseInt(tokens[1]); 13 | dc.write(tokens[0] + " " + (n * (n + 1) / 2 + n) + "\n"); 14 | } 15 | 16 | dc.close(); 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/checkingforcorrectness.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.util.*; 4 | 5 | public class checkingforcorrectness { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc = new Scanner(System.in); 8 | StringBuilder out = new StringBuilder(); 9 | BigInteger MOD = BigInteger.valueOf(10000); 10 | while (sc.hasNext()) { 11 | BigInteger a = sc.nextBigInteger(); 12 | char op = sc.next().charAt(0); 13 | BigInteger b = sc.nextBigInteger(); 14 | BigInteger res; 15 | if (op == '+') 16 | res = a.add(b).mod(MOD); 17 | else if (op == '*') 18 | res = a.multiply(b).mod(MOD); 19 | else 20 | res = a.modPow(b, MOD); 21 | out.append(res).append('\n'); 22 | } 23 | System.out.println(out); 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/cold.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/cold 3 | import java.util.Scanner; 4 | 5 | public class cold { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | int count = 0; 11 | while (cases-- > 0) 12 | if (sc.nextInt() < 0) 13 | count++; 14 | System.out.println(count); 15 | sc.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/combinationlock.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class combinationlock { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String line; 10 | while (!(line = sc.readLine()).equals("0 0 0 0")) { 11 | String[] arr = line.split(" "); 12 | int start = Integer.parseInt(arr[0]); 13 | int a = Integer.parseInt(arr[1]), b = Integer.parseInt(arr[2]), c = Integer.parseInt(arr[3]); 14 | int degrees = 1080; 15 | final int dpt = 9; 16 | if (a > start) 17 | start += 40; 18 | degrees += (start - a) * dpt; 19 | if (a > b) 20 | a -= 40; 21 | degrees += (b - a) * dpt; 22 | if (c > b) 23 | b += 40; 24 | degrees += (b - c) * dpt; 25 | dc.write(degrees + "\n"); 26 | } 27 | 28 | dc.close(); 29 | sc.close(); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/compoundwords.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/compoundwords 3 | import java.util.Scanner; 4 | import java.util.TreeSet; 5 | 6 | public class compoundwords { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | TreeSet parts = new TreeSet<>(); 11 | while (sc.hasNextLine()) { 12 | String[] line = sc.nextLine().split(" "); 13 | for (String s : line) 14 | parts.add(s); 15 | } 16 | TreeSet words = new TreeSet<>(); 17 | for (String s : parts) { 18 | for (String a : parts) { 19 | if (!s.equals(a)) 20 | words.add(s + a); 21 | } 22 | } 23 | for (String s : words) 24 | System.out.println(s); 25 | 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/conundrum.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/conundrum 3 | import java.util.Scanner; 4 | 5 | public class conundrum { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String code = sc.nextLine(); 10 | int days = 0; 11 | for (int s = 0; s < code.length(); s += 3) { 12 | if (code.charAt(s) != 'P') 13 | days++; 14 | if (code.charAt(s + 1) != 'E') 15 | days++; 16 | if (code.charAt(s + 2) != 'R') 17 | days++; 18 | } 19 | System.out.println(days); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/costumecontest.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class costumecontest { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | TreeMap map = new TreeMap<>(); 9 | while (n-- > 0) { 10 | String s = sc.next(); 11 | map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1); 12 | } 13 | int min = 10000; 14 | for (String key : map.keySet()) 15 | min = Math.min(min, map.get(key)); 16 | for (String key : map.keySet()) 17 | if (map.get(key) == min) 18 | System.out.println(key); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/cups.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/cups 3 | import java.util.Map; 4 | import java.util.Scanner; 5 | import java.util.TreeMap; 6 | 7 | public class cups { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | TreeMap orderOfCups = new TreeMap<>(); 12 | int cups = sc.nextInt(); 13 | sc.nextLine(); 14 | while (cups-- > 0) { 15 | String line = sc.nextLine(); 16 | String[] description = line.split(" "); 17 | int radius; 18 | String color; 19 | 20 | if ((int) description[0].charAt(0) >= 48 && (int) description[0].charAt(0) <= 57) { 21 | radius = Integer.parseInt(description[0])/2; 22 | color = description[1]; 23 | } else { 24 | radius = Integer.parseInt(description[1]); 25 | color = description[0]; 26 | } 27 | orderOfCups.put(radius, color); 28 | } 29 | for (Map.Entry s : orderOfCups.entrySet()) 30 | System.out.println(s.getValue()); 31 | sc.close(); 32 | } 33 | } -------------------------------------------------------------------------------- /Java/deathknight.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/deathknight 3 | import java.util.Scanner; 4 | 5 | public class deathknight { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int battles = sc.nextInt(); 10 | int won = 0; 11 | sc.nextLine(); 12 | while (battles-- > 0) { 13 | String abilities = sc.nextLine(); 14 | if (!abilities.contains("CD")) 15 | won++; 16 | } 17 | System.out.println(won); 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/detaileddifferences.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/detaileddifferences 3 | import java.util.Scanner; 4 | 5 | public class detaileddifferences { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | String pair1 = sc.next(); 12 | String pair2 = sc.next(); 13 | System.out.println(pair1 + "\n" + pair2); 14 | for (int x = 0; x < pair1.length(); x++) { 15 | if (pair1.charAt(x) == pair2.charAt(x)) 16 | System.out.print("."); 17 | else 18 | System.out.print("*"); 19 | } 20 | System.out.println("\n"); 21 | } 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/different.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/different 3 | import java.util.Scanner; 4 | 5 | public class different { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | while (sc.hasNextLong()) 10 | System.out.println(Math.abs(sc.nextLong() - sc.nextLong())); 11 | 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/differentdistances.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/differentdistances 3 | import java.util.Scanner; 4 | 5 | public class differentdistances { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | while (true) { 10 | String temp = sc.nextLine(); 11 | if (temp.equals("0")) 12 | break; 13 | String[] nums = temp.split(" "); 14 | double p = Double.parseDouble(nums[4]); 15 | double x = Math.pow(Math.abs(Double.parseDouble(nums[0]) - Double.parseDouble(nums[2])), p); 16 | double y = Math.pow(Math.abs(Double.parseDouble(nums[1]) - Double.parseDouble(nums[3])), p); 17 | System.out.printf("%.10f\n", Math.pow(x + y, 1 / p)); 18 | } 19 | sc.close(); 20 | } 21 | } -------------------------------------------------------------------------------- /Java/digits.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class digits { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | for (;;) { 8 | String line = sc.next(); 9 | if (line.equals("END")) 10 | break; 11 | if (line.equals("1")) { 12 | System.out.println(1); 13 | continue; 14 | } 15 | int i = 2; 16 | int prev = line.length(); 17 | int cur = (int) Math.log10(prev) + 1; 18 | while (cur != prev) { 19 | prev = cur; 20 | cur = (int) Math.log10(prev) + 1; 21 | i++; 22 | } 23 | System.out.println(i); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Java/downtime.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class downtime { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int[] arr = new int[101001]; 8 | int n = sc.nextInt(); 9 | int k = sc.nextInt(); 10 | while (n-- > 0) { 11 | int a = sc.nextInt(); 12 | arr[a]++; 13 | arr[a + 1000]--; 14 | } 15 | double max = 0; 16 | for (int x = 1; x < arr.length; x++) 17 | max = Math.max(max, arr[x] += arr[x - 1]); 18 | System.out.println((int) Math.ceil(max / k)); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/encodedmessage.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/encodedmessage 3 | import java.util.Scanner; 4 | 5 | public class encodedmessage { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | sc.nextLine(); 11 | while (cases-- > 0) { 12 | char[] encoded = sc.nextLine().toCharArray(); 13 | int side = (int) Math.sqrt(encoded.length); 14 | char[][] letters = new char[side][side]; 15 | int i = 0; 16 | for (int row = 0; row < side; row++) 17 | for (int col = 0; col < side; col++) 18 | letters[row][col] = encoded[i++]; 19 | 20 | for (int col = side - 1; col >= 0; col--) 21 | for (int row = 0; row < side; row++) 22 | System.out.print(letters[row][col]); 23 | System.out.println(); 24 | } 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /Java/engineeringenglish.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/engineeringenglish 3 | import java.util.HashSet; 4 | import java.util.Scanner; 5 | 6 | public class engineeringenglish { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | HashSet words = new HashSet<>(); 11 | while (sc.hasNextLine()) { 12 | for (String s : sc.nextLine().split(" ")) 13 | if (words.contains(s.toLowerCase())) 14 | System.out.print(". "); 15 | else { 16 | System.out.print(s + " "); 17 | words.add(s.toLowerCase()); 18 | } 19 | System.out.println(); 20 | } 21 | sc.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/epigdanceoff.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class epigdanceoff { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int m = sc.nextInt(); 9 | int[] arr = new int[m]; 10 | for (int x = 0; x < n; x++) { 11 | char[] line = sc.next().toCharArray(); 12 | for (int a = 0; a < m; a++) 13 | if (line[a] == '_') 14 | arr[a]++; 15 | } 16 | int count = 0; 17 | for (int x : arr) 18 | if (x == n) 19 | count++; 20 | System.out.println(count + 1); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/erase.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class erase { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | sc.nextLine(); 9 | String a = sc.nextLine(); 10 | String b = sc.nextLine(); 11 | if ((n & 1) == 1) 12 | System.out.println(a.replace('1', ' ').replace('0', '1').replace(' ', '0').equals(b) ? "Deletion succeeded" 13 | : "Deletion failed"); 14 | else 15 | System.out.println(a.equals(b) ? "Deletion succeeded" : "Deletion failed"); 16 | sc.close(); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/eulersnumber.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class eulersnumber { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int n = Integer.parseInt(sc.readLine()); 10 | double sum = 1, prev = 1; 11 | for (int x = 1; x <= n; x++) 12 | sum += prev *= 1d / x; 13 | dc.write(sum + "\n"); 14 | 15 | dc.close(); 16 | sc.close(); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/everywhere.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/everywhere 3 | import java.util.HashSet; 4 | import java.util.Scanner; 5 | 6 | public class everywhere { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | while (cases-- > 0) { 12 | HashSet cities = new HashSet<>(); 13 | int trips = sc.nextInt(); 14 | while (trips-- > 0) 15 | cities.add(sc.next()); 16 | System.out.println(cities.size()); 17 | } 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/faktor.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/faktor 3 | import java.util.Scanner; 4 | 5 | public class faktor { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int articles = sc.nextInt(); 10 | int impact = sc.nextInt() - 1; 11 | System.out.println(articles * impact + 1); 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/filip.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/filip 3 | import java.util.Scanner; 4 | 5 | public class filip { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String temp1 = new StringBuffer(sc.next()).reverse().toString(); 10 | String temp2 = new StringBuffer(sc.next()).reverse().toString(); 11 | int fnum = Integer.parseInt(temp1); 12 | int snum = Integer.parseInt(temp2); 13 | System.out.println(fnum > snum ? fnum : snum); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/fizzbuzz.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/fizzbuzz 3 | import java.util.Scanner; 4 | 5 | public class fizzbuzz { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int x = sc.nextInt(); 10 | int y = sc.nextInt(); 11 | int n = sc.nextInt() + 1; 12 | 13 | for (int d = 1; d < n; d++) 14 | System.out.println(d % x == 0 && d % y == 0 ? "FizzBuzz" 15 | : d % x == 0 && d % y != 0 ? "Fizz" : d % x != 0 && d % y == 0 ? "Buzz" : Integer.toString(d)); 16 | sc.close(); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/freefood.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class freefood { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int events = sc.nextInt(); 8 | int min = 400, max = -1; 9 | boolean[] free = new boolean[366]; 10 | while (events-- > 0) { 11 | int a = sc.nextInt(); 12 | int b = sc.nextInt(); 13 | min = Math.min(min, a); 14 | max = Math.max(max, b); 15 | for (; a <= b; a++) 16 | free[a] = true; 17 | } 18 | int days = 0; 19 | for (; min <= max; min++) 20 | if (free[min]) 21 | days++; 22 | System.out.println(days); 23 | sc.close(); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/froshweek2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class froshweek2 { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int N = sc.nextInt(), M = sc.nextInt(); 8 | int[] taskTime = new int[N]; 9 | int[] quietTime = new int[M]; 10 | for (int x = 0; x < N; x++) 11 | taskTime[x] = sc.nextInt(); 12 | for (int x = 0; x < M; x++) 13 | quietTime[x] = sc.nextInt(); 14 | Arrays.sort(taskTime); 15 | Arrays.sort(quietTime); 16 | int count = 0; 17 | for (int a = 0, b = 0; a < M && b < N;) { 18 | if (taskTime[b] <= quietTime[a]) { 19 | b++; 20 | a++; 21 | count++; 22 | } else 23 | a++; 24 | } 25 | System.out.println(count); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/grassseed.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/grassseed 3 | import java.util.Scanner; 4 | 5 | public class grassseed { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | double cost = sc.nextDouble(); 10 | int cases = sc.nextInt(); 11 | double area = 0; 12 | while (cases-- > 0) { 13 | double width = sc.nextDouble(); 14 | double length = sc.nextDouble(); 15 | area += width * length; 16 | } 17 | System.out.printf("%.7f", area * cost); 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/guess.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/guess 3 | import java.util.Scanner; 4 | 5 | public class guess { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int min = 1; 10 | int max = 1000; 11 | while (true) { 12 | int guess = (min + max) / 2; 13 | System.out.println(guess); 14 | String reply = sc.nextLine(); 15 | if (reply.equals("correct")) 16 | break; 17 | else if (reply.equals("lower")) 18 | max = guess - 1; 19 | else if (reply.equals("higher")) 20 | min = guess + 1; 21 | } 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/guessinggame.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class guessinggame { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int min = 0, max = 11, num; 10 | for (;;) { 11 | num = Integer.parseInt(sc.readLine()); 12 | if (num == 0) 13 | break; 14 | String response = sc.readLine(); 15 | if (response.equals("right on")) { 16 | dc.write(min < num && num < max ? "Stan may be honest\n" : "Stan is dishonest\n"); 17 | min = 0; 18 | max = 11; 19 | continue; 20 | } else if (response.equals("too high")) 21 | max = Math.min(max, num); 22 | else 23 | min = Math.max(min, num); 24 | } 25 | 26 | dc.close(); 27 | sc.close(); 28 | } 29 | } -------------------------------------------------------------------------------- /Java/hangingout.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/hangingout 3 | import java.util.Scanner; 4 | 5 | public class hangingout { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int limit = sc.nextInt(); 10 | int events = sc.nextInt(); 11 | int terace = 0; 12 | int cantGo = 0; 13 | while (events-- > 0) { 14 | String status = sc.next(); 15 | int people = sc.nextInt(); 16 | if (status.equals("enter") && terace + people <= limit) 17 | terace += people; 18 | else if (status.equals("leave")) 19 | terace -= people; 20 | else 21 | cantGo++; 22 | } 23 | System.out.println(cantGo); 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/hangman.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class hangman { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.next(); 8 | char[] arr = sc.next().toCharArray(); 9 | int count = 0; 10 | for (int x = 0; x < arr.length; x++) { 11 | if (s.contains(arr[x] + "")) 12 | s = s.replace(arr[x] + "", ""); 13 | else 14 | count++; 15 | if (s.length() == 0) { 16 | System.out.println("WIN"); 17 | return; 18 | } else if (count == 10) { 19 | System.out.println("LOSE"); 20 | return; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Java/hello.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/hello 3 | 4 | public class hello { 5 | public static void main(String[] args) { 6 | System.out.println("Hello World!"); 7 | } 8 | } -------------------------------------------------------------------------------- /Java/helpaphd.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/helpaphd 3 | import java.util.Scanner; 4 | 5 | public class helpaphd { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | sc.nextLine(); 11 | while (cases-- > 0) { 12 | String line = sc.nextLine(); 13 | if (line.contains("P=NP")) 14 | System.out.println("skipped"); 15 | else { 16 | int plus = line.indexOf("+"); 17 | int fnum = Integer.parseInt(line.substring(0, plus)); 18 | int snum = Integer.parseInt(line.substring(plus)); 19 | System.out.println(fnum + snum); 20 | } 21 | } 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/herman.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/herman 3 | import java.util.Scanner; 4 | 5 | public class herman { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int radius = sc.nextInt(); 10 | double area = Math.PI * Math.pow(radius, 2); 11 | double taxiArea = Math.pow(radius, 2) * 2; 12 | System.out.printf("%.6f\n", area); 13 | System.out.printf("%.6f", taxiArea); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/hidden.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class hidden { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String[] tokens = sc.readLine().split(" "); 10 | char[] arr = tokens[1].toCharArray(); 11 | String result = ""; 12 | for (int x = 0; x < tokens[0].length(); x++) { 13 | check: { 14 | for (int a = 0; a < arr.length; a++) 15 | for (int d = x; d < tokens[0].length(); d++) 16 | if (arr[a] == tokens[0].charAt(d)) { 17 | result += arr[a]; 18 | arr[a] = ' '; 19 | break check; 20 | } 21 | } 22 | } 23 | dc.write(result.equals(tokens[0]) ? "PASS" : "FAIL"); 24 | 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/hissingmicrophone.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/hissingmicrophone 3 | import java.util.Scanner; 4 | 5 | public class hissingmicrophone { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | System.out.println(sc.nextLine().contains("ss") ? "hiss" : "no hiss"); 10 | sc.close(); 11 | } 12 | } -------------------------------------------------------------------------------- /Java/hothike.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class hothike { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int[] arr = new int[n]; 9 | for (int x = 0; x < n; x++) 10 | arr[x] = sc.nextInt(); 11 | int t = Integer.MAX_VALUE; 12 | int d = 0; 13 | for (int x = 0; x < n - 2; x++) 14 | if (Math.max(arr[x], arr[x + 2]) < t) { 15 | t = Math.max(arr[x], arr[x + 2]); 16 | d = x + 1; 17 | } 18 | System.out.println(d + " " + t); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/icpcawards.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/icpcawards 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class icpcawards { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | LinkedHashMap teams = new LinkedHashMap<>(); 11 | 12 | int cases = sc.nextInt(); 13 | sc.nextLine(); 14 | while (cases-- > 0) { 15 | String place = sc.next(); 16 | String name = " " + sc.next(); 17 | if (!teams.containsKey(place) && teams.size() < 12) 18 | teams.put(place, name); 19 | } 20 | for (Map.Entry s : teams.entrySet()) 21 | System.out.println(s.getKey() + s.getValue()); 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/integerdivision.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class integerdivision { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int d = sc.nextInt(); 9 | HashMap map = new HashMap<>(); 10 | while (n-- > 0) { 11 | int a = sc.nextInt() / d; 12 | map.put(a, map.containsKey(a) ? map.get(a) + 1 : 1L); 13 | } 14 | long count = 0; 15 | for (int k : map.keySet()) { 16 | long v = map.get(k); 17 | count += v * (v - 1) / 2; 18 | } 19 | System.out.println(count); 20 | } 21 | } -------------------------------------------------------------------------------- /Java/isithalloween.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class isithalloween { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String s = sc.readLine(); 10 | dc.write(s.equals("OCT 31") || s.equals("DEC 25") ? "yup" : "nope"); 11 | 12 | dc.close(); 13 | sc.close(); 14 | } 15 | } -------------------------------------------------------------------------------- /Java/janitortroubles.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class janitortroubles { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | double s = 0; 8 | int[] a = new int[4]; 9 | for (int x = 0; x < 4; x++) { 10 | a[x] = sc.nextInt(); 11 | s += a[x]; 12 | } 13 | s /= 2; 14 | double res = 1; 15 | for (int x = 0; x < 4; x++) 16 | res *= s - a[x]; 17 | System.out.println(Math.sqrt(res)); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/jobexpenses.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class jobexpenses { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int sum = 0; 9 | while (n-- > 0) 10 | sum = Math.max(sum, sum - sc.nextInt()); 11 | System.out.println(sum); 12 | } 13 | } -------------------------------------------------------------------------------- /Java/judgingmoose.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/judgingmoose 3 | import java.util.Scanner; 4 | 5 | public class judgingmoose { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int left = sc.nextInt(); 10 | int right = sc.nextInt(); 11 | 12 | System.out.println(left == 0 && right == 0 ? "Not a moose" 13 | : left == right ? "Even " + (left + right) : left > right ? "Odd " + (left * 2) : "Odd " + (right * 2)); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/justaminute.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/justaminute 3 | import java.util.Scanner; 4 | 5 | public class justaminute { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | int min = 0; 11 | int sec = 0; 12 | while (cases-- > 0) { 13 | min += sc.nextInt() * 60; 14 | sec += sc.nextInt(); 15 | } 16 | if (min >= sec) 17 | System.out.println("measurement error"); 18 | else 19 | System.out.printf("%.9f", (double) sec / min); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/kemija08.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/kemija08 3 | import java.util.Scanner; 4 | 5 | public class kemija08 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; 10 | String sentence = sc.nextLine(); 11 | String decode = ""; 12 | for (int x = 0; x < sentence.length(); x++) { 13 | for (int z = 0; z < vowels.length; z++) { 14 | if (sentence.charAt(x) == vowels[z]) 15 | x += 2; 16 | } 17 | decode += sentence.charAt(x); 18 | } 19 | System.out.println(decode); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/kornislav.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/kornislav 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class kornislav { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int[] nums = new int[4]; 11 | for (int x = 0; x < nums.length; x++) 12 | nums[x] = sc.nextInt(); 13 | Arrays.sort(nums); 14 | System.out.println(nums[0] * nums[2]); 15 | sc.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/ladder.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/ladder 3 | import java.util.Scanner; 4 | 5 | public class ladder { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int opposite = sc.nextInt(); 9 | int angle = sc.nextInt(); 10 | 11 | double adjacent = opposite / Math.tan(Math.toRadians(angle)); 12 | double hypot = Math.sqrt(Math.pow(opposite, 2) + Math.pow(adjacent, 2)); 13 | System.out.println((int) Math.ceil(hypot)); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/lastfactorialdigit.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class lastfactorialdigit { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int[] arr = new int[11]; 10 | arr[1] = 1; 11 | for (int x = 2; x < arr.length; x++) 12 | arr[x] = ((arr[x - 1] % 10) * (x % 10)) % 10; 13 | 14 | int cases = Integer.parseInt(sc.readLine()); 15 | while (cases-- > 0) 16 | dc.write(arr[Integer.parseInt(sc.readLine())] + "\n"); 17 | 18 | dc.close(); 19 | sc.close(); 20 | } 21 | } -------------------------------------------------------------------------------- /Java/limbo1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.math.*; 4 | 5 | public class limbo1 { 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 8 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 9 | 10 | BigInteger two = new BigInteger("2"); 11 | 12 | int cases = Integer.parseInt(sc.readLine()); 13 | while (cases-- > 0) { 14 | String[] nums = sc.readLine().split(" "); 15 | BigInteger left = new BigInteger(nums[0]); 16 | BigInteger right = new BigInteger(nums[1]); 17 | 18 | // gauss formulas 19 | // 1 + (left * (left + 1)) / 2 20 | // (right * (left + left + right + 3)) / 2 21 | 22 | BigInteger val1 = BigInteger.ONE.add(left.multiply(left.add(BigInteger.ONE)).divide(two)); 23 | BigInteger val2 = right.multiply(left.add(left.add(right.add(BigInteger.ONE.add(two))))).divide(two); 24 | dc.write(val1.add(val2).toString() + "\n"); 25 | } 26 | 27 | dc.close(); 28 | sc.close(); 29 | } 30 | } -------------------------------------------------------------------------------- /Java/listgame.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/listgame 3 | 4 | import java.io.BufferedReader; 5 | import java.io.BufferedWriter; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.io.OutputStreamWriter; 9 | 10 | public class listgame { 11 | public static void main(String[] args) throws IOException { 12 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 13 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 14 | 15 | int num = Integer.parseInt(sc.readLine()); 16 | int count = 0; 17 | 18 | while (num % 2 == 0) { 19 | num /= 2; 20 | count++; 21 | } 22 | 23 | for (int x = 3; x <= (int) Math.sqrt(num); x += 2) 24 | while (num % x == 0) { 25 | num /= x; 26 | count++; 27 | } 28 | 29 | if (num > 2) 30 | count++; 31 | 32 | dc.write(count + "\n"); 33 | 34 | dc.flush(); 35 | dc.close(); 36 | sc.close(); 37 | } 38 | } -------------------------------------------------------------------------------- /Java/lostlineup.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class lostlineup { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt() - 1; 8 | int[] arr = new int[n]; 9 | for (int x = 1; x <= n; x++) 10 | arr[sc.nextInt()] = x + 1; 11 | System.out.print(1 + " "); 12 | for (int x : arr) 13 | System.out.print(x + " "); 14 | } 15 | } -------------------------------------------------------------------------------- /Java/mastermind.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class mastermind { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int[] q = new int['Z' + 1]; 8 | int[] w = new int['Z' + 1]; 9 | int n = sc.nextInt(); 10 | char[] a = sc.next().toCharArray(); 11 | char[] b = sc.next().toCharArray(); 12 | int r = 0; 13 | int s = 0; 14 | for (int x = 0; x < n; x++) { 15 | if (a[x] == b[x]) 16 | r++; 17 | else { 18 | q[a[x]]++; 19 | w[b[x]]++; 20 | } 21 | } 22 | for (int x = 'A'; x <= 'Z'; x++) 23 | s += Math.min(q[x], w[x]); 24 | System.out.println(r + " " + s); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/mirror.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/mirror 3 | import java.util.Scanner; 4 | 5 | public class mirror { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | for (int x = 1; x <= cases; x++) { 11 | int rows = sc.nextInt(); 12 | sc.nextLine(); 13 | String[] order = new String[rows]; 14 | int index = 0; 15 | while (rows-- > 0) { 16 | String pattern = new StringBuffer(sc.nextLine()).reverse().toString(); 17 | order[index] = pattern; 18 | index++; 19 | } 20 | System.out.println("Test " + x); 21 | for (int a = order.length - 1; a >= 0; a--) 22 | System.out.println(order[a]); 23 | } 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/missingnumbers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class missingnumbers { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | boolean[] arr = new boolean[201]; 8 | int n = sc.nextInt(); 9 | int last = 0; 10 | while (n-- > 0) { 11 | int x = sc.nextInt(); 12 | arr[x] = true; 13 | last = x; 14 | } 15 | boolean fail = false; 16 | for (int x = 1; x <= last; x++) { 17 | if (!arr[x]) { 18 | fail = true; 19 | System.out.println(x); 20 | } 21 | } 22 | if (!fail) 23 | System.out.println("good job"); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/mixedfractions.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/mixedfractions 3 | import java.util.Scanner; 4 | 5 | public class mixedfractions { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | while (true) { 10 | double n = sc.nextDouble(); 11 | double d = sc.nextDouble(); 12 | if (n == 0 && d == 0) 13 | break; 14 | System.out.println( 15 | d > n ? "0 " + (int) n + " / " + (int) d : (int) (n / d) + " " + (int) (n % d) + " / " + (int) d); 16 | } 17 | 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/mjehuric.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class mjehuric { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String[] line = sc.nextLine().split(" "); 8 | int[] arr = new int[line.length]; 9 | for (int x = 0; x < line.length; x++) 10 | arr[x] = Integer.parseInt(line[x]); 11 | int x = 0; 12 | boolean done = false; 13 | while (!done) { 14 | done = true; 15 | for (int a = 0; a < arr.length - 1; a++) { 16 | if (arr[a] > arr[a + 1]) { 17 | int t = arr[a]; 18 | arr[a] = arr[a + 1]; 19 | arr[a + 1] = t; 20 | for (int q = 0; q < arr.length; q++) 21 | System.out.print(arr[q] + " "); 22 | System.out.println(); 23 | done = false; 24 | } 25 | } 26 | x++; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Java/modulo.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/modulo 3 | import java.util.HashSet; 4 | import java.util.Scanner; 5 | 6 | public class modulo { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | HashSet modulo = new HashSet<>(); 10 | 11 | for (int x = 0; x < 10; x++) 12 | modulo.add(sc.nextInt() % 42); 13 | System.out.println(modulo.size()); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/moscowdream.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class moscowdream { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int a = sc.nextInt(); 8 | int b = sc.nextInt(); 9 | int c = sc.nextInt(); 10 | int n = sc.nextInt(); 11 | System.out.println(a > 0 && b > 0 && c > 0 && a + b + c >= n && n >= 3 ? "YES" : "NO"); 12 | } 13 | } -------------------------------------------------------------------------------- /Java/mosquito.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class mosquito { 5 | static int M, P, L, E, R, S, N; 6 | 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc = new Scanner(System.in); 9 | while (sc.hasNextInt()) { 10 | M = sc.nextInt(); 11 | P = sc.nextInt(); 12 | L = sc.nextInt(); 13 | E = sc.nextInt(); 14 | R = sc.nextInt(); 15 | S = sc.nextInt(); 16 | N = sc.nextInt(); 17 | while (N-- > 0) { 18 | int p = L / R; 19 | int m = P / S; 20 | int l = M * E; 21 | L = l; 22 | P = p; 23 | M = m; 24 | } 25 | System.out.println(M); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Java/nastyhacks.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/nastyhacks 3 | import java.util.Scanner; 4 | 5 | public class nastyhacks { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | int noAdvertise = sc.nextInt(); 12 | int ifAdvertise = sc.nextInt(); 13 | int cost = sc.nextInt(); 14 | System.out.println(noAdvertise == ifAdvertise - cost ? "does not matter" 15 | : noAdvertise > ifAdvertise - cost ? "do not advertise" : "advertise"); 16 | } 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/natrij.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class natrij { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String[] cur = sc.nextLine().split(":"); 8 | String[] end = sc.nextLine().split(":"); 9 | int current = Integer.parseInt(cur[0]) * 3600 + Integer.parseInt(cur[1]) * 60 + Integer.parseInt(cur[2]); 10 | int endtime = Integer.parseInt(end[0]) * 3600 + Integer.parseInt(end[1]) * 60 + Integer.parseInt(end[2]); 11 | int duration; 12 | if (current < endtime) 13 | duration = endtime - current; 14 | else 15 | duration = 24 * 3600 - current + endtime; 16 | int hours = duration / 3600; 17 | duration %= 3600; 18 | int mins = duration / 60; 19 | System.out.printf("%02d:%02d:%02d", hours, mins, duration % 60); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/nodup.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/nodup 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.Scanner; 6 | 7 | public class nodup { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | String[] words = sc.nextLine().split(" "); 12 | HashSet noDup = new HashSet<>(Arrays.asList(words)); 13 | System.out.println(words.length == noDup.size() ? "yes" : "no"); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/numberfun.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/numberfun 3 | import java.util.Scanner; 4 | 5 | public class numberfun { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while(cases-- > 0) { 11 | double fnum = sc.nextDouble(); 12 | double snum = sc.nextDouble(); 13 | double tnum = sc.nextDouble(); 14 | System.out.println(fnum + snum == tnum || Math.abs(fnum - snum) == tnum || fnum * snum == tnum || fnum / snum == tnum || snum / fnum == tnum ? "Possible" : "Impossible"); 15 | } 16 | sc.close(); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/oddgnome.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/oddgnome 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | 6 | public class oddgnome { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | sc.nextLine(); 12 | while (cases-- > 0) { 13 | ArrayList gnomes = new ArrayList<>(); 14 | String[] nums = sc.nextLine().split(" "); 15 | for (int x = 0; x < nums.length; x++) 16 | gnomes.add(Integer.parseInt(nums[x])); 17 | gnomes.remove(0); 18 | gnomes.remove(gnomes.size() - 1); 19 | for (int x = 0; x < gnomes.size(); x++) 20 | if (gnomes.get(x + 1) - gnomes.get(x) != 1) { 21 | System.out.println(x + 2); 22 | break; 23 | } 24 | } 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /Java/oddities.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/oddities 3 | import java.util.Scanner; 4 | 5 | public class oddities { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | int num = sc.nextInt(); 12 | System.out.println(num % 2 == 0 ? num + " is even" : num + " is odd"); 13 | } 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/oddmanout.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/oddmanout 3 | import java.util.Scanner; 4 | 5 | public class oddmanout { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | for (int a = 1; a <= cases; a++) { 11 | int guestsNum = sc.nextInt(); 12 | int[] guests = new int[guestsNum]; 13 | for (int x = 0; x < guests.length; x++) 14 | guests[x] = sc.nextInt(); 15 | for (int x : guests) { 16 | int count = 0; 17 | for (int z : guests) 18 | if (z == x) 19 | count++; 20 | if (count == 1) 21 | System.out.println("Case #" + a + ": " + x); 22 | } 23 | } 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/onechicken.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/onechicken 3 | import java.util.Scanner; 4 | 5 | public class onechicken { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int people = sc.nextInt(); 10 | int chicken = sc.nextInt(); 11 | 12 | int p = chicken - people; 13 | int q = people - chicken; 14 | 15 | System.out.println(people < chicken 16 | ? p == 1 ? "Dr. Chaz will have " + p + " piece of chicken left over!" 17 | : "Dr. Chaz will have " + p + " pieces of chicken left over!" 18 | : q == 1 ? "Dr. Chaz needs " + q + " more piece of chicken!" 19 | : "Dr. Chaz needs " + q + " more pieces of chicken!"); 20 | 21 | sc.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/ostgotska.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/ostgotska 3 | import java.util.Scanner; 4 | 5 | public class ostgotska { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String[] words = sc.nextLine().split(" "); 10 | double count = 0; 11 | for (String s : words) 12 | if (s.contains("ae")) 13 | count++; 14 | System.out.println(count / words.length >= .4 ? "dae ae ju traeligt va" : "haer talar vi rikssvenska"); 15 | sc.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java/owlandfox.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class owlandfox { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int cases = sc.nextInt(); 8 | while (cases-- > 0) { 9 | int n = sc.nextInt(); 10 | int t = n; 11 | int pow = 1; 12 | while (t % 10 == 0) { 13 | pow *= 10; 14 | t /= 10; 15 | } 16 | System.out.println(n - pow); 17 | } 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/pairingsocks.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class pairingsocks { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | Stack a = new Stack<>(); 9 | for (int x = 0; x < n * 2; x++) { 10 | int q = sc.nextInt(); 11 | if (a.isEmpty() || a.peek() != q) 12 | a.push(q); 13 | else 14 | a.pop(); 15 | } 16 | System.out.println(a.isEmpty() ? n * 2 + "" : "impossible"); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/parking2.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/parking2 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class parking2 { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | while (cases-- > 0) { 12 | int stores = sc.nextInt(); 13 | int[] position = new int[stores]; 14 | for (int x = 0; x < stores; x++) 15 | position[x] = sc.nextInt(); 16 | Arrays.sort(position); 17 | 18 | int distance = 0; 19 | for (int x = 1; x <= stores; x++) 20 | distance += x == stores ? position[x - 1] - position[0] : position[x] - position[x - 1]; 21 | System.out.println(distance); 22 | } 23 | 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/perket.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class perket { 5 | static int n; 6 | static int[][] arr; 7 | 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc = new Scanner(System.in); 10 | n = sc.nextInt(); 11 | arr = new int[n][2]; 12 | for (int x = 0; x < n; x++) { 13 | arr[x][0] = sc.nextInt(); 14 | arr[x][1] = sc.nextInt(); 15 | } 16 | System.out.println(rec(0, 1, 0)); 17 | } 18 | 19 | static int rec(int index, int res1, int res2) { 20 | if (index == n) 21 | return res1 == 1 && res2 == 0 ? Integer.MAX_VALUE : Math.abs(res1 - res2); 22 | return Math.min(rec(index + 1, res1 * arr[index][0], res2 + arr[index][1]), rec(index + 1, res1, res2)); 23 | } 24 | } -------------------------------------------------------------------------------- /Java/pet.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/pet 3 | import java.util.Scanner; 4 | import java.util.TreeMap; 5 | 6 | public class pet { 7 | public static void main(String[] args) { 8 | TreeMap points = new TreeMap<>(); 9 | Scanner sc = new Scanner(System.in); 10 | 11 | for (int x = 1; x < 6; x++) { 12 | int total = 0; 13 | total += sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt(); 14 | points.put(total, x); 15 | } 16 | System.out.println(points.get(points.lastKey()) + " " + points.lastKey()); 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/phonelist.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/phonelist 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class phonelist { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | while (cases-- > 0) { 12 | int phones = sc.nextInt(); 13 | sc.nextLine(); 14 | String[] nums = new String[phones]; 15 | for (int x = 0; x < phones; x++) 16 | nums[x] = sc.nextLine(); 17 | Arrays.sort(nums); 18 | boolean noPrefix = true; 19 | for (int x = 0; x < phones - 1; x++) 20 | if (nums[x + 1].startsWith(nums[x])) { 21 | noPrefix = false; 22 | break; 23 | } 24 | System.out.println(noPrefix ? "YES" : "NO"); 25 | } 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/pieceofcake2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class pieceofcake2 { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int h = sc.nextInt(); 9 | int v = sc.nextInt(); 10 | System.out.println(Math.max(h, n - h) * Math.max(v, n - v) * 4); 11 | } 12 | } -------------------------------------------------------------------------------- /Java/pizza2.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/pizza2 3 | import java.util.Scanner; 4 | 5 | public class pizza2 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int radius = sc.nextInt(); 10 | int cheese = radius - sc.nextInt(); 11 | 12 | double area = Math.pow(radius, 2) * Math.PI; 13 | double cheeseArea = Math.pow(cheese, 2) * Math.PI; 14 | double percent = (cheeseArea / area) * 100; 15 | System.out.printf("%.6f", percent); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java/planina.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/planina 3 | import java.util.Scanner; 4 | 5 | public class planina { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int iterations = sc.nextInt(); 10 | int side = 2; 11 | while (iterations-- > 0) 12 | side += side - 1; 13 | System.out.println((int) Math.pow(side, 2)); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/pokerhand.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class pokerhand { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int[] arr = new int[100]; 10 | int max = -1, c = ' '; 11 | for (String s : sc.readLine().split(" ")) 12 | if (++arr[c = s.charAt(0)] > max) 13 | max = arr[c]; 14 | dc.write(max + "\n"); 15 | 16 | dc.close(); 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/pot.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/pot 3 | import java.util.Scanner; 4 | 5 | public class pot { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | int total = 0; 11 | sc.nextLine(); 12 | 13 | while (cases-- > 0) { 14 | String line = sc.nextLine(); 15 | int num = Integer.parseInt(line.substring(0, line.length() - 1)); 16 | int power = Integer.parseInt(line.substring(line.length() - 1)); 17 | total += Math.pow(num, power); 18 | } 19 | System.out.println(total); 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/ptice.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class ptice { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | String[] keys = { "ABC", "BABC", "CCAABB" }; 8 | int n = sc.nextInt(); 9 | String ans = sc.next(); 10 | int[] count = new int[3]; 11 | for (int x = 0; x < n; x++) { 12 | char c = ans.charAt(x); 13 | for (int i = 0; i < 3; i++) 14 | if (c == keys[i].charAt(x % keys[i].length())) 15 | count[i]++; 16 | } 17 | int max = 0; 18 | for (int x = 0; x < 3; x++) 19 | max = Math.max(max, count[x]); 20 | System.out.println(max); 21 | for (int x = 0; x < 3; x++) { 22 | if (max == count[x]) { 23 | if (x == 0) 24 | System.out.println("Adrian"); 25 | else if (x == 1) 26 | System.out.println("Bruno"); 27 | else 28 | System.out.println("Goran"); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Java/qaly.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class qaly { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int cases = Integer.parseInt(sc.readLine()); 10 | double sum = 0; 11 | while (cases-- > 0) { 12 | String[] tokens = sc.readLine().split(" "); 13 | sum += Double.parseDouble(tokens[0]) * Double.parseDouble(tokens[1]); 14 | } 15 | dc.write(sum + "\n"); 16 | 17 | dc.close(); 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/quadrant.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/quadrant 3 | import java.util.Scanner; 4 | 5 | public class quadrant { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int x = sc.nextInt(); 10 | int y = sc.nextInt(); 11 | 12 | System.out.println((x > 0 && y > 0) ? 1 : (x < 0 && y < 0) ? 3 : (x > 0 && y < 0) ? 4 : 2); 13 | sc.close(); 14 | } 15 | } -------------------------------------------------------------------------------- /Java/quickestimate.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/quickestimate 3 | import java.util.Scanner; 4 | 5 | public class quickestimate { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | sc.nextLine(); 11 | while (cases-- > 0) 12 | System.out.println(sc.nextLine().length()); 13 | sc.close(); 14 | } 15 | } -------------------------------------------------------------------------------- /Java/r2.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/r2 3 | import java.util.Scanner; 4 | 5 | public class r2 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int fnum = sc.nextInt(); 10 | int mean = sc.nextInt(); 11 | System.out.println((mean * 2) - fnum); 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/racingalphabet.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class racingalphabet { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | final String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ '"; 10 | 11 | int cases = Integer.parseInt(sc.readLine()); 12 | while (cases-- > 0) { 13 | String line = sc.readLine(); 14 | double sum = 0; 15 | for (int x = 1, prev = alpha.indexOf(line.charAt(0)); x < line.length(); x++) { 16 | int loc = alpha.indexOf(line.charAt(x)); 17 | int dist1 = Math.abs(prev - loc); 18 | int dist2 = 28 - dist1; 19 | sum += Math.min(dist1, dist2); 20 | prev = loc; 21 | } 22 | dc.write(Math.PI * sum / 7 + line.length() + "\n"); 23 | } 24 | 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/raggedright.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.BufferedWriter; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.OutputStreamWriter; 6 | import java.util.ArrayList; 7 | 8 | public class raggedright { 9 | public static void main(String[] args) throws IOException { 10 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 11 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 12 | 13 | ArrayList lengths = new ArrayList<>(); 14 | int max = 0; 15 | 16 | while (sc.ready()) { 17 | int len = sc.readLine().length(); 18 | if (len > max) 19 | max = len; 20 | lengths.add(len); 21 | } 22 | 23 | int sum = 0; 24 | for (int x = 0; x < lengths.size() - 1; x++) { 25 | int amt = max - lengths.get(x); 26 | sum += (amt * amt); 27 | } 28 | 29 | dc.write(sum + "\n"); 30 | 31 | dc.flush(); 32 | dc.close(); 33 | sc.close(); 34 | } 35 | } -------------------------------------------------------------------------------- /Java/railroad2.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/railroad2 3 | import java.util.Scanner; 4 | 5 | public class railroad2 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | sc.nextInt(); 10 | System.out.println(sc.nextInt() % 2 == 0 ? "possible" : "impossible"); 11 | 12 | sc.close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Java/recount.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class recount { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | HashMap map = new HashMap<>(); 8 | int max = -1; 9 | String winner = null; 10 | for (;;) { 11 | String name = sc.nextLine(); 12 | if (name.equals("***")) 13 | break; 14 | map.put(name, map.containsKey(name) ? map.get(name) + 1 : 1); 15 | int val = map.get(name); 16 | if (val > max) { 17 | winner = name; 18 | max = val; 19 | } else if (val == max) { 20 | winner = null; 21 | } 22 | } 23 | System.out.println(winner == null ? "Runoff!" : winner); 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/rectanglesurrounding.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class rectanglesurrounding { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | for (;;) { 8 | int n = sc.nextInt(); 9 | if (n == 0) 10 | break; 11 | boolean[][] arr = new boolean[501][501]; 12 | while (n-- > 0) { 13 | int r1 = sc.nextInt(); 14 | int c1 = sc.nextInt(); 15 | int r2 = sc.nextInt(); 16 | int c2 = sc.nextInt(); 17 | for (int r = r1; r < r2; r++) 18 | for (int c = c1; c < c2; c++) 19 | arr[r][c] = true; 20 | } 21 | int count = 0; 22 | for (boolean[] r : arr) 23 | for (boolean c : r) 24 | if (c) 25 | count++; 26 | System.out.println(count); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Java/repeatingdecimal.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/repeatingdecimal 3 | import java.util.Scanner; 4 | 5 | public class repeatingdecimal { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // long division 10 | while (sc.hasNextInt()) { 11 | int a = sc.nextInt() * 10; 12 | int b = sc.nextInt(); 13 | int c = sc.nextInt(); 14 | System.out.print("0."); 15 | while (c-- > 0) { 16 | System.out.print(a / b); 17 | a %= b; 18 | a *= 10; 19 | } 20 | System.out.println(); 21 | } 22 | sc.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Java/reversebinary.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/reversebinary 3 | import java.util.Scanner; 4 | 5 | public class reversebinary { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String binary = Integer.toBinaryString(sc.nextInt()); 10 | String swap = ""; 11 | for (int s = binary.length() - 1; 0 <= s; s--) 12 | swap += binary.charAt(s); 13 | System.out.println(Integer.parseInt(swap, 2)); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/reverserot.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/reverserot 3 | import java.util.Scanner; 4 | 5 | public class reverserot { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_."; 9 | 10 | while (true) { 11 | int rot = sc.nextInt(); 12 | if (rot == 0) 13 | break; 14 | char[] arr = sc.nextLine().substring(1).toCharArray(); 15 | String decode = ""; 16 | for (int a = arr.length - 1; a >= 0; a--) { 17 | int index = 0; 18 | for (int x = 0; x < alpha.length(); x++) 19 | if (alpha.charAt(x) == arr[a]) { 20 | index = x + rot; 21 | break; 22 | } 23 | index %= alpha.length(); 24 | decode += alpha.charAt(index); 25 | } 26 | System.out.println(decode); 27 | } 28 | sc.close(); 29 | } 30 | } -------------------------------------------------------------------------------- /Java/rijeci.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/rijeci 3 | import java.util.Scanner; 4 | 5 | public class rijeci { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int pressed = sc.nextInt(); 10 | int[] ab = fib(pressed); 11 | System.out.println(ab[0] + " " + ab[1]); 12 | 13 | sc.close(); 14 | } 15 | 16 | private static int[] fib(int a) { 17 | int[] f = new int[a + 1]; 18 | f[0] = 0; 19 | f[1] = 1; 20 | 21 | for (int x = 2; x <= a; x++) 22 | f[x] = f[x - 1] + f[x - 2]; 23 | 24 | int[] s = { f[a - 1], f[a] }; 25 | return s; 26 | } 27 | } -------------------------------------------------------------------------------- /Java/romans.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class romans { 5 | public static void main(String[] args) throws Exception { 6 | System.out 7 | .println(Math.round(Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine()) 8 | * 1000 * 5280 / 4854)); 9 | } 10 | } -------------------------------------------------------------------------------- /Java/sevenwonders.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/sevenwonders 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class sevenwonders { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | String letters = sc.nextLine(); 11 | int[] counts = { 0, 0, 0 }; 12 | for (int x = 0; x < letters.length(); x++) { 13 | if (letters.charAt(x) == 'T') 14 | counts[0]++; 15 | else if (letters.charAt(x) == 'C') 16 | counts[1]++; 17 | else 18 | counts[2]++; 19 | } 20 | Arrays.sort(counts); 21 | System.out.println( 22 | (int) (Math.pow(counts[0], 2) + Math.pow(counts[1], 2) + Math.pow(counts[2], 2) + (counts[0] * 7))); 23 | sc.close(); 24 | } 25 | } -------------------------------------------------------------------------------- /Java/shatteredcake.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/shatteredcake 3 | import java.util.Scanner; 4 | 5 | public class shatteredcake { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int width = sc.nextInt(); 10 | int pieces = sc.nextInt(); 11 | int area = 0; 12 | while (pieces-- > 0) { 13 | area += sc.nextInt() * sc.nextInt(); 14 | } 15 | System.out.println(area / width); 16 | 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java/shopaholic.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class shopaholic { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int size = sc.nextInt(); 8 | Long[] arr = new Long[size]; 9 | for (int x = 0; x < size; x++) 10 | arr[x] = sc.nextLong(); 11 | Arrays.sort(arr, new Comparator() { 12 | public int compare(Long a, Long b) { 13 | return a < b ? 1 : a > b ? -1 : 0; 14 | } 15 | }); 16 | long discount = 0; 17 | for (int x = 0; x < size; x++) 18 | if (x % 3 == 2) 19 | discount += arr[x]; 20 | System.out.println(discount); 21 | sc.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/sibice.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/sibice 3 | import java.util.Scanner; 4 | 5 | public class sibice { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int matches = sc.nextInt(); 10 | int width = sc.nextInt(); 11 | int height = sc.nextInt(); 12 | while (matches-- > 0) 13 | System.out.println(sc.nextInt() <= Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) ? "DA" : "NE"); 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/sidewayssorting.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class sidewayssorting { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | for (;;) { 8 | int row = sc.nextInt(), col = sc.nextInt(); 9 | if (row == 0 && col == 0) 10 | break; 11 | sc.nextLine(); 12 | String[] arr = new String[col]; 13 | for (int r = 0; r < row; r++) { 14 | String line = sc.nextLine(); 15 | for (int c = 0; c < col; c++) { 16 | if (r == 0) 17 | arr[c] = ""; 18 | arr[c] += line.charAt(c); 19 | } 20 | } 21 | Arrays.sort(arr, String.CASE_INSENSITIVE_ORDER); 22 | for (int r = 0; r < row; r++) { 23 | for (int c = 0; c < col; c++) 24 | System.out.print(arr[c].charAt(r)); 25 | System.out.println(); 26 | } 27 | System.out.println(); 28 | } 29 | sc.close(); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/simon.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/simon 3 | import java.util.Scanner; 4 | 5 | public class simon { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | sc.nextLine(); 11 | while (cases-- > 0) { 12 | String line = sc.nextLine(); 13 | System.out.println(line.contains("simon says") && line.length() > 11 ? line.substring(11) : ""); 14 | } 15 | sc.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/simonsays.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/simonsays 3 | import java.util.Scanner; 4 | 5 | public class simonsays { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | sc.nextLine(); 11 | while (cases-- > 0) { 12 | String command = sc.nextLine(); 13 | if (command.contains("Simon says")) 14 | System.out.println(command.substring(11)); 15 | } 16 | sc.close(); 17 | } 18 | } -------------------------------------------------------------------------------- /Java/skocimis.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/skocimis 3 | import java.util.Scanner; 4 | 5 | public class skocimis { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int first = sc.nextInt(); 10 | int mid = sc.nextInt(); 11 | int last = sc.nextInt(); 12 | 13 | int fdiff = mid - first - 1; 14 | int sdiff = last - mid - 1; 15 | 16 | System.out.println(fdiff > sdiff ? fdiff : sdiff); 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java/slatkisi.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class slatkisi { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String[] tokens = sc.readLine().split(" "); 10 | int price = Integer.parseInt(tokens[0]); 11 | int zeros = Integer.parseInt(tokens[1]); 12 | dc.write(round(price, zeros) + "\n"); 13 | dc.close(); 14 | sc.close(); 15 | } 16 | 17 | private static int round(int num, int places) { 18 | double pow = Math.pow(10, places); 19 | return (int) (Math.round(num / pow) * pow); 20 | } 21 | } -------------------------------------------------------------------------------- /Java/smallestmultiple.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.math.*; 4 | 5 | public class smallestmultiple { 6 | public static void main(String[] args) throws Exception { 7 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 8 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 9 | 10 | String line; 11 | while ((line = sc.readLine()) != null) { 12 | String[] nums = line.split(" "); 13 | dc.write(lcm(nums) + "\n"); 14 | dc.flush(); 15 | } 16 | 17 | dc.close(); 18 | sc.close(); 19 | } 20 | 21 | private static BigInteger lcm(BigInteger a, BigInteger b) { 22 | return a.multiply(b).divide(a.gcd(b)); 23 | } 24 | 25 | private static String lcm(String[] arr) { 26 | BigInteger res = new BigInteger(arr[0]); 27 | for (int x = 1; x < arr.length; x++) 28 | res = lcm(res, new BigInteger(arr[x])); 29 | return res.toString(); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/somesum.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class somesum { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | if (n == 1) { 9 | System.out.println("Either"); 10 | return; 11 | } 12 | double half = n / 2d; 13 | int h1 = (int) Math.floor(half); 14 | int h2 = (int) Math.ceil(half); 15 | if (h1 == h2) 16 | if (h1 % 2 == 1) 17 | System.out.println("Odd"); 18 | else 19 | System.out.println("Even"); 20 | else 21 | System.out.println("Either"); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/soylent.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/soylent 3 | import java.util.Scanner; 4 | 5 | public class soylent { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | int caloriesNeed = sc.nextInt(); 12 | int calories = 0; 13 | int cups = 0; 14 | while (calories < caloriesNeed) { 15 | calories += 400; 16 | cups++; 17 | } 18 | System.out.println(cups); 19 | } 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/soyoulikeyourfoodhot.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class soyoulikeyourfoodhot { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | int total = (int) fix(sc.nextDouble() * 100); 9 | int a = (int) fix(sc.nextDouble() * 100); 10 | int b = (int) fix(sc.nextDouble() * 100); 11 | int count = 0; 12 | HashMap map = new HashMap<>(); 13 | for (int x = 0; x <= total / b; x++) 14 | map.put(x * b, x); 15 | for (int x = 0; x <= total / a; x++) { 16 | int val = x * a; 17 | if (map.containsKey(total - val)) { 18 | count++; 19 | dc.write(x + " " + map.get(total - val) + "\n"); 20 | } 21 | } 22 | if (count == 0) 23 | dc.write("none\n"); 24 | sc.close(); 25 | dc.close(); 26 | } 27 | 28 | private static double fix(double a) { 29 | return Math.round(a * 100) / 100d; 30 | } 31 | } -------------------------------------------------------------------------------- /Java/spavanac.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/spavanac 3 | import java.util.Scanner; 4 | 5 | public class spavanac { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int hour = sc.nextInt(); 10 | int min = sc.nextInt() - 45; 11 | if (min < 0) { 12 | min += 60; 13 | hour--; 14 | if (hour < 0) 15 | hour = 23; 16 | } 17 | System.out.println(hour + " " + min); 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/speedlimit.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/speedlimit 3 | import java.util.Scanner; 4 | 5 | public class speedlimit { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | boolean isNegOne = false; 10 | while (!isNegOne) { 11 | int pairs = sc.nextInt(); 12 | if (pairs == -1) { 13 | isNegOne = true; 14 | } else { 15 | int[] speedTime = new int[pairs * 2]; 16 | for (int x = 0; x < speedTime.length; x++) 17 | speedTime[x] = sc.nextInt(); 18 | 19 | int distance = speedTime[0] * speedTime[1]; 20 | for (int s = 2; s < speedTime.length; s += 2) 21 | distance += (speedTime[s + 1] - speedTime[s - 1]) * speedTime[s]; 22 | System.out.println(distance + " miles"); 23 | } 24 | } 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /Java/stararrangements.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/stararrangements 3 | import java.util.Scanner; 4 | 5 | public class stararrangements { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | double stars = sc.nextDouble(); 10 | System.out.println((int) stars + ":"); 11 | for (int x = 2; x < Math.round(stars / 2) + 1; x++) { 12 | int y = x - 1; 13 | if (stars % (x + y) == x || stars % (x + y) == 0) 14 | System.out.println(x + "," + y); 15 | if (stars % x == 0) 16 | System.out.println(x + "," + x); 17 | } 18 | sc.close(); 19 | } 20 | } -------------------------------------------------------------------------------- /Java/sumkindofproblem.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/sumkindofproblem 3 | import java.util.Scanner; 4 | 5 | public class sumkindofproblem { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int cases = sc.nextInt(); 10 | while (cases-- > 0) { 11 | int caseNum = sc.nextInt(); 12 | System.out.print(caseNum + " "); 13 | int num = sc.nextInt(); 14 | int sum = 0; 15 | for (int x = 1; x <= num; x++) 16 | sum += x; 17 | System.out.print(sum + " " + ((sum * 2) - num) + " " + (sum * 2) + "\n"); 18 | } 19 | sc.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Java/sumoftheothers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class sumoftheothers { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in), 1 << 16); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out), 1 << 16); 8 | String line; 9 | while ((line = sc.readLine()) != null) { 10 | String[] arr = line.split(" "); 11 | int[] nums = new int[arr.length]; 12 | int total = 0; 13 | for (int x = 0; x < arr.length; x++) { 14 | nums[x] = Integer.parseInt(arr[x]); 15 | total += nums[x]; 16 | } 17 | for (int x = 0; x < arr.length; x++) { 18 | int num = nums[x]; 19 | if (num == total - num) { 20 | dc.write(num + "\n"); 21 | break; 22 | } 23 | } 24 | } 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } -------------------------------------------------------------------------------- /Java/sumsquareddigits.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class sumsquareddigits { 5 | public static void main(String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | int cases = Integer.parseInt(sc.readLine()); 10 | while (cases-- > 0) { 11 | String[] tokens = sc.readLine().split(" "); 12 | int base = Integer.parseInt(tokens[1]); 13 | long num = Long.parseLong(tokens[2]); 14 | long sum = 0; 15 | while (num > 0) { 16 | int dig = (int) num % base; 17 | sum += dig * dig; 18 | num = (num - dig) / base; 19 | } 20 | dc.write(tokens[0] + " " + sum + "\n"); 21 | } 22 | 23 | dc.close(); 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /Java/supercomputer.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class supercomputer { 5 | static int n; 6 | static int[] arr; 7 | static boolean[] state; 8 | 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc = new Scanner(System.in); 11 | n = sc.nextInt(); 12 | int k = sc.nextInt(); 13 | arr = new int[n + 1]; 14 | state = new boolean[n + 1]; 15 | while (k-- > 0) { 16 | char q = sc.next().charAt(0); 17 | if (q == 'F') { 18 | int x = sc.nextInt(); 19 | state[x] = !state[x]; 20 | upd(x, state[x] ? 1 : -1); 21 | } else { 22 | int l = sc.nextInt(); 23 | int r = sc.nextInt(); 24 | System.out.println(qry(r) - qry(l - 1)); 25 | } 26 | } 27 | } 28 | 29 | static void upd(int i, int val) { 30 | for (; i <= n; i += i & -i) 31 | arr[i] += val; 32 | } 33 | 34 | static int qry(int i) { 35 | int sum = 0; 36 | for (; i > 0; i -= i & -i) 37 | sum += arr[i]; 38 | return sum; 39 | } 40 | } -------------------------------------------------------------------------------- /Java/symmetricorder.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/symmetricorder 3 | import java.util.Scanner; 4 | 5 | public class symmetricorder { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int set = 1; 10 | while (true) { 11 | int cases = sc.nextInt(); 12 | if (cases == 0) 13 | break; 14 | sc.nextLine(); 15 | String[] names = new String[cases / 2]; 16 | System.out.println("SET " + set); 17 | 18 | for (int x = names.length - 1; x >= 0; x--) { 19 | System.out.println(sc.nextLine()); 20 | names[x] = sc.nextLine(); 21 | } 22 | 23 | if (cases % 2 == 1) 24 | System.out.println(sc.nextLine()); 25 | 26 | for (String s : names) 27 | System.out.println(s); 28 | 29 | set++; 30 | } 31 | sc.close(); 32 | } 33 | } -------------------------------------------------------------------------------- /Java/taisformula.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class taisformula { 4 | public static void main(String[] args) throws Exception { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt() - 1; 7 | double total = 0, t0 = sc.nextDouble(), v0 = sc.nextDouble(); 8 | while (n-- > 0) { 9 | double t = sc.nextDouble(), v = sc.nextDouble(); 10 | total += (v + v0) / 2 * ((t - t0) / 1000); 11 | t0 = t; 12 | v0 = v; 13 | } 14 | System.out.println(total); 15 | sc.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/tarifa.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/tarifa 3 | import java.util.*; 4 | 5 | public class tarifa { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int amount = sc.nextInt(); 10 | int lines = sc.nextInt(); 11 | int nextMonth = amount; 12 | while (lines-- > 0) { 13 | int s = sc.nextInt(); 14 | nextMonth += (amount - s); 15 | } 16 | System.out.println(nextMonth); 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /Java/teacherevaluation.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class teacherevaluation { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int p = sc.nextInt(); 9 | if (p == 100) { 10 | System.out.println("impossible"); 11 | return; 12 | } 13 | int sum = 0; 14 | for (int x = 0; x < n; x++) 15 | sum += sc.nextInt(); 16 | long lo = n + 1; 17 | long hi = (int) 1e6; 18 | long ans = 0; 19 | while (lo < hi) { 20 | long m = (lo + hi) / 2; 21 | long add = m - n; 22 | long total = add * 100 + sum; 23 | if (total / (double) m >= p) { 24 | ans = add; 25 | hi = m; 26 | } else { 27 | lo = m + 1; 28 | } 29 | } 30 | System.out.println(ans); 31 | } 32 | } -------------------------------------------------------------------------------- /Java/tetration.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/tetration 3 | import java.util.Scanner; 4 | 5 | public class tetration { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | double a = sc.nextDouble(); 10 | System.out.printf("%.6f", Math.pow(a, 1 / a)); 11 | 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/thebackslashproblem.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class thebackslashproblem { 4 | public static void main(String[] args) throws Exception { 5 | Scanner sc = new Scanner(System.in); 6 | while (sc.hasNextLine()) { 7 | int n = sc.nextInt(); 8 | sc.nextLine(); 9 | String line = sc.nextLine(); 10 | while (n-- > 0) { 11 | line = line.replace("\\", "\\\\"); 12 | line = line.replace("!", "\\!"); 13 | line = line.replace("\"", "\\\""); 14 | line = line.replace("#", "\\#"); 15 | line = line.replace("$", "\\$"); 16 | line = line.replace("%", "\\%"); 17 | line = line.replace("&", "\\&"); 18 | line = line.replace("'", "\\'"); 19 | line = line.replace("(", "\\("); 20 | line = line.replace(")", "\\)"); 21 | line = line.replace("*", "\\*"); 22 | line = line.replace("[", "\\["); 23 | line = line.replace("]", "\\]"); 24 | } 25 | System.out.println(line); 26 | } 27 | sc.close(); 28 | } 29 | } -------------------------------------------------------------------------------- /Java/thegrandadventure.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class thegrandadventure { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int[] map = new int[200]; 8 | map['b'] = '$'; 9 | map['t'] = '|'; 10 | map['j'] = '*'; 11 | int n = sc.nextInt(); 12 | while (n-- > 0) { 13 | char[] arr = sc.next().replace(".", "").toCharArray(); 14 | Stack s = new Stack<>(); 15 | boolean fail = false; 16 | for (int x = 0; x < arr.length; x++) 17 | if (map[arr[x]] > 0) { 18 | if (s.isEmpty() || map[arr[x]] != s.peek()) { 19 | System.out.println("NO"); 20 | fail = true; 21 | break; 22 | } else 23 | s.pop(); 24 | } else 25 | s.push(arr[x]); 26 | if (!fail) 27 | System.out.println(s.isEmpty() ? "YES" : "NO"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Java/throwns.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class throwns { 5 | static int n; 6 | 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc = new Scanner(System.in); 9 | n = sc.nextInt(); 10 | int k = sc.nextInt(); 11 | Stack s = new Stack<>(); 12 | int cur = 0; 13 | while (k-- > 0) { 14 | String a = sc.next(); 15 | if (a.matches("-?\\d+")) { 16 | int q = Integer.parseInt(a); 17 | s.push(q); 18 | cur += q; 19 | } else { 20 | int t = sc.nextInt(); 21 | while (t-- > 0) 22 | cur -= s.pop(); 23 | } 24 | } 25 | System.out.println(mod(cur)); 26 | } 27 | 28 | static int mod(int a) { 29 | while (a < 0) 30 | a += n; 31 | a %= n; 32 | return a; 33 | } 34 | } -------------------------------------------------------------------------------- /Java/timeloop.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/timeloop 3 | import java.util.Scanner; 4 | 5 | public class timeloop { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int num = sc.nextInt(); 10 | for (int i = 1; i <= num; i++) 11 | System.out.println(i + " Abracadabra"); 12 | sc.close(); 13 | } 14 | } -------------------------------------------------------------------------------- /Java/tiredterry.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class tiredterry { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int p = sc.nextInt(); 9 | int d = sc.nextInt(); 10 | String s = sc.next(); 11 | int[] arr = new int[n << 1]; 12 | for (int x = 0; x < arr.length; x++) 13 | if (s.charAt(x % n) == 'Z') 14 | arr[x]++; 15 | for (int x = 1; x < arr.length; x++) 16 | arr[x] += arr[x - 1]; 17 | int count = 0; 18 | for (int x = n; x < arr.length; x++) 19 | if (arr[x] - arr[x - p] < d) 20 | count++; 21 | System.out.println(count); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/tolower.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/tolower 3 | import java.util.Scanner; 4 | 5 | public class tolower { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int problems = sc.nextInt(); 10 | int cases = sc.nextInt(); 11 | int max = problems; 12 | sc.nextLine(); 13 | for (int x = 0; x < problems; x++) { 14 | boolean moreUpper = false; 15 | for (int a = 0; a < cases; a++) { 16 | String line = sc.nextLine(); 17 | if (!moreUpper) { 18 | char[] chars = line.toCharArray(); 19 | for (int s = 1; s < chars.length; s++) { 20 | if (Character.isUpperCase(chars[s])) { 21 | moreUpper = true; 22 | break; 23 | } 24 | } 25 | } 26 | } 27 | if (moreUpper) 28 | max--; 29 | } 30 | System.out.println(max); 31 | sc.close(); 32 | } 33 | } -------------------------------------------------------------------------------- /Java/trik.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/trik 3 | import java.util.Scanner; 4 | 5 | public class trik { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int[] position = { 1, 0, 0 }; 10 | String moves = sc.nextLine(); 11 | for (int x = 0; x < moves.length(); x++) { 12 | if (moves.charAt(x) == 'A') { 13 | int temp = position[1]; 14 | position[1] = position[0]; 15 | position[0] = temp; 16 | } else if (moves.charAt(x) == 'B') { 17 | int temp = position[1]; 18 | position[1] = position[2]; 19 | position[2] = temp; 20 | } else if (moves.charAt(x) == 'C') { 21 | int temp = position[0]; 22 | position[0] = position[2]; 23 | position[2] = temp; 24 | } 25 | } 26 | System.out.println(position[0] == 1 ? 1 : position[1] == 1 ? 2 : 3); 27 | sc.close(); 28 | } 29 | } -------------------------------------------------------------------------------- /Java/tripletexting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(0); 8 | string s; 9 | cin >> s; 10 | int len = s.size() / 3; 11 | set m; 12 | auto f = [&]() { 13 | for (int x = 0; x < s.size(); x += len) { 14 | string sub = s.substr(x, len); 15 | if (m.find(sub) != m.end()) { 16 | cout << sub; 17 | return; 18 | } else { 19 | m.insert(sub); 20 | } 21 | } 22 | }; 23 | f(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Java/twostones.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/twostones 3 | import java.util.Scanner; 4 | 5 | public class twostones { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | System.out.println(n % 2 == 0 ? "Bob" : "Alice"); 11 | sc.close(); 12 | } 13 | } -------------------------------------------------------------------------------- /Java/unlockpattern.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class unlockpattern { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int[][] arr = new int[3][3]; 8 | int[] f = new int[2]; 9 | for (int r = 0; r < 3; r++) 10 | for (int c = 0; c < 3; c++) { 11 | arr[r][c] = sc.nextInt(); 12 | if (arr[r][c] == 1) { 13 | f[0] = r; 14 | f[1] = c; 15 | } 16 | } 17 | double dist = 0; 18 | for (int x = 1; x < 9; x++) { 19 | int[] s = new int[2]; 20 | for (int r = 0; r < 3; r++) 21 | for (int c = 0; c < 3; c++) 22 | if (arr[r][c] == x + 1) { 23 | s[0] = r; 24 | s[1] = c; 25 | } 26 | dist += Math.sqrt(Math.pow(s[0] - f[0], 2) + Math.pow(s[1] - f[1], 2)); 27 | f = s; 28 | } 29 | System.out.println(dist); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/vacuumba.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class vacuumba { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int cases = sc.nextInt(); 8 | while (cases-- > 0) { 9 | int lines = sc.nextInt(); 10 | double x = 0, y = 0; 11 | double cur = 0; 12 | while (lines-- > 0) { 13 | double angle = -sc.nextDouble(); 14 | double dist = sc.nextDouble(); 15 | cur += angle; 16 | x += dist * Math.sin(Math.toRadians(cur)); 17 | y += dist * Math.cos(Math.toRadians(cur)); 18 | } 19 | System.out.printf("%.6f %.6f\n", x, y); 20 | } 21 | sc.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/vote.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class vote { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc = new Scanner(System.in); 7 | int cases = sc.nextInt(); 8 | while (cases-- > 0) { 9 | int size = sc.nextInt(); 10 | int total = 0; 11 | int max = 0; 12 | int[] arr = new int[size]; 13 | HashMap map = new HashMap<>(); 14 | for (int x = 0; x < size; x++) { 15 | total += arr[x] = sc.nextInt(); 16 | max = Math.max(max, arr[x]); 17 | map.put(arr[x], map.containsKey(arr[x]) ? map.get(arr[x]) + 1 : 1); 18 | } 19 | if (map.get(max) > 1) { 20 | System.out.println("no winner"); 21 | continue; 22 | } 23 | for (int x = 0; x < size; x++) 24 | if (arr[x] == max) { 25 | System.out.println((max > total / 2d ? "majority " : "minority ") + "winner " + (x + 1)); 26 | break; 27 | } 28 | } 29 | sc.close(); 30 | } 31 | } -------------------------------------------------------------------------------- /Java/zanzibar.java: -------------------------------------------------------------------------------- 1 | 2 | // https://open.kattis.com/problems/zanzibar 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | 6 | public class zanzibar { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int cases = sc.nextInt(); 11 | while (cases-- > 0) { 12 | ArrayList numOfTurtles = new ArrayList<>(); 13 | while (true) { 14 | int turtle = sc.nextInt(); 15 | if (turtle == 0) 16 | break; 17 | numOfTurtles.add(turtle); 18 | } 19 | int imports = 0; 20 | for (int x = 0; x < numOfTurtles.size() - 1; x++) 21 | if (numOfTurtles.get(x) * 2 < numOfTurtles.get(x + 1)) 22 | imports += (numOfTurtles.get(x + 1) - numOfTurtles.get(x) * 2); 23 | System.out.println(imports); 24 | } 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /Java/zoo.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class zoo { 5 | public static void main (String[] args) throws Exception { 6 | BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); 7 | BufferedWriter dc = new BufferedWriter(new OutputStreamWriter(System.out)); 8 | 9 | String line; 10 | int i = 1; 11 | while (!(line = sc.readLine()).equals("0")) { 12 | TreeMap map = new TreeMap<>(); 13 | int cases = Integer.parseInt(line); 14 | while (cases-- > 0) { 15 | String[] tokens = sc.readLine().split(" "); 16 | String animal = tokens[tokens.length - 1].toLowerCase(); 17 | map.put(animal, map.containsKey(animal) ? map.get(animal) + 1 : 1); 18 | } 19 | dc.write("List " + i++ + ":\n"); 20 | for (Map.Entry s : map.entrySet()) 21 | dc.write(s.getKey() + " | " + s.getValue() + "\n"); 22 | dc.flush(); 23 | } 24 | 25 | dc.close(); 26 | sc.close(); 27 | } 28 | } 29 | --------------------------------------------------------------------------------