├── Kattis-Solutions ├── BergMal.py ├── Lubbi Laerir.py ├── Bitte Ein Bit.py ├── Vidsnuningur.py ├── Kvedja.py ├── Tolvunarfraedingar Telja.py ├── Hipp Hipp.py ├── Draga Fra.py ├── Flatbokuveisla.py ├── Reduplication.py ├── Til Hamingju.py ├── Pinni Fraendi.py ├── Framtidar FIFA.py ├── A Shortcut to What.py ├── A Leid I Bio.py ├── Storafmaeli.py ├── Peach Powder Polygon.py ├── Takk fyrir mig.py ├── Fimmtudagstilbod.py ├── Hipp Hipp Hurra.py ├── Ekki Daudi Opna Inni.py ├── Pizza Crust.cpp ├── Pallatolur.py ├── Buka.py ├── Skocimis.cpp ├── Aaah.cpp ├── Shandy.py ├── A Real Challenge.cpp ├── Takkar.py ├── Stafur.py ├── Stuck In A Time Loop.cs ├── Ullen Dullen Doff.py ├── Take Two Stones.go ├── A Second Opinion.py ├── Call for Problems.py ├── Multiplications.py ├── Three in a Row.py ├── Bishops.cpp ├── Fyrirtaekjanafn.py ├── Adding Trouble.go ├── Quick Estimates.cpp ├── FYI.cs ├── Metronome.cs ├── Autori.go ├── Kinahvisl.py ├── Herman.cpp ├── A Different Problem.cpp ├── Hradgreining.py ├── Rijeci.cpp ├── Server.cpp ├── The Last Problem.cs ├── Two-sum.cs ├── Umferd.py ├── Besta Gjofin.py ├── Canadians Eh.cs ├── Soylent.go ├── Turn it up.py ├── Basketball One-on-One.cs ├── CPR Number.py ├── Dagatal.py ├── Is Y a Vowel.py ├── Kornislav.cpp ├── Arithmetic Functions.cpp ├── Different Distances.cpp ├── Maddelande.py ├── Spritt.py ├── Decimal Deletion.cs ├── Triple Sevens.py ├── Job Expenses.cpp ├── Revision Control.py ├── Estimating the Area of a Circle.cpp ├── Oddities.cpp ├── Digit Swap.cs ├── Grass Seed Inc.go ├── Translation.py ├── Knight Packing.cs ├── Champernowne Verification.py ├── Detailed Differences.cpp ├── International Dates.dart ├── Jack O Lantern Juxtaposition.cs ├── Trapizza.py ├── Faktor.cpp ├── Greetings.cs ├── Mixed Fractions.cpp ├── GCD.cs ├── Ladder.cpp ├── Pencil Crayons.py ├── N Sum.cs ├── Reverse.cs ├── Seven Wonders.cpp ├── Triangle Area.cs ├── Another Candies.cpp ├── Sort Two Numbers.cs ├── Hailstone Sequence.py ├── Fjoldi Bokstafa.py ├── Hakkari.py ├── License to Launch.cpp ├── Divvying Up.cs ├── Dice Cup.go ├── IsItHalloween.cs ├── Mirror Images.cpp ├── Spavanac.cpp ├── Cetvrta.cpp ├── Symmetric Order.cpp ├── Heliocentric.cpp ├── Barcelona.py ├── Daylight Saving Time.cpp ├── No Duplicates.cpp ├── Cosmic Path Optimization.cs ├── Zoom.cpp ├── Booking a Room.cpp ├── Radio Commercials.cpp ├── Cetiri.cpp ├── Sibice.go ├── Backspace.cpp ├── Laptop Sticker.cs ├── Quadrant Selection.cpp ├── Chanukah Challenge.cs ├── Prsteni.cpp ├── Ostgotska.go ├── Square Peg.cs ├── Volim.cpp ├── Beavergnaw.cpp ├── Shattered Cake.cs ├── Tok Tik.py ├── Cryptographers Conundrum.cpp ├── Tower Construction.cs ├── 99 Problems.cs ├── GCVWR.cs ├── Undead or Alive.go ├── Attendance.py ├── Howl.cs ├── Vauvau.cpp ├── Building Pyramids.cs ├── Pokechat.cs ├── Modulo.cs ├── R2.cpp ├── Sticky Keys.cs ├── Stopwatch.cs ├── Keys Phone Wallet.py ├── Trik.cpp ├── Simple Addition.java ├── Soda Slurper.cs ├── Triple Texting.cs ├── Nasty Hacks.cpp ├── Judging Troubles.py ├── Minimum Scalar Product.cpp ├── Peragram.cpp ├── Planina.cpp ├── Magic Trick.cs ├── Synchronizing List.cpp ├── Class Field Trip.cs ├── Piece of Cake.cs ├── I've Been Everywhere Man.cpp ├── Kafkaesque.cs ├── Keywords.cs ├── Rectangle Area.cs ├── Tri.cpp ├── Minesweeper.py ├── Hissing Microphone.cpp ├── Candy Store.py ├── Cokolada.cpp ├── Tajna.cpp ├── Verify This, Your Majesty.cpp ├── Saving for Retirement.cpp ├── Test Drive.cs ├── I Hate The Number Nine.java ├── Knot Knowledge.cs ├── Overdraft.cs ├── Sum Kind of Problem.go ├── Disc District.cs ├── Ragged Right.cs ├── Reseto.cpp ├── Vedur Lokadar Heidar.cs ├── No Thanks.cs ├── Climbing Worm.cs ├── Powers of Two Easy.cs ├── Das Blinkenlights.cs ├── Digit Product.cs ├── Almost Perfect.cpp ├── Falling Apart.cpp ├── Patuljci.cpp ├── Provinces and Gold.cs ├── Zamka.cpp ├── Encoded Message.cpp ├── Exactly Electrical.cpp ├── Jabuke.cpp ├── Secret Message.cpp ├── Tarifa.cpp ├── Black Friday.cpp ├── Engineering English.cpp ├── Fifty Shades of Pink.cs ├── SMIL.cs ├── Left Beehind.cpp ├── Speed Limit.cpp ├── Semafori.go ├── Honour Thy Apaxian Parent.cs ├── Bijele.cpp ├── Forced Choice.cs ├── Goldbach's Conjecture.cpp ├── From A to B.cs ├── Odd Man Out.cpp ├── Unlock Pattern.cpp ├── Line Them Up.cs ├── Eye of Sauron.cs ├── Vacuumba.cpp ├── Mars Window.cpp ├── Moscow Dream.cs ├── Planting Trees.cpp ├── Akcija.cpp ├── Babelfish.cs ├── Bus Numbers.cpp ├── Delicious Bubble Tea.cpp ├── Unbearable Zoo.cs ├── Haughty Cuisine.cs ├── Pot.cs ├── Permuted Arithmetic Sequence.cpp ├── Saving Daylight.cs ├── Coffee Cup Combo.cs ├── Paradox With Averages.cpp ├── Mastering Mastermind.cpp ├── Event Planning.cs ├── Popular Vote.cpp ├── Paradox With Averages (Hard).cpp ├── Death Knight Hero.cpp ├── Electrical Outlets.cs ├── Heirs Dilemma.cs └── Grading.cs ├── README.md ├── Hackerrank ├── A Very Big Sum.cpp ├── Minimum Draws.cpp ├── Staircase.cpp ├── Equalize the Array.cpp ├── Bigger is Greater.cpp ├── Grading Students.go ├── Bon Appetit.cpp ├── Camel Case.cs ├── Handshake.cpp ├── Viral Advertising.cpp ├── Solve Me First.cs ├── Birthday Cake Candles.cpp ├── Find the Median.cpp ├── Game of Stones.cs ├── Apple and Orange.cpp ├── Repeated String.cpp ├── Intro to Tutorial Challenges.cpp ├── Flipping Bits.cpp ├── Minimum Distances.cpp ├── Connecting Towns.cpp ├── Counting Sort 1.cpp ├── Angry Professor.cpp ├── Divisible Sum Pairs.cpp ├── Taum and B'day.cpp ├── Sherlock and The Beast.cpp ├── Diagonal Difference.cpp ├── Service Lane.cpp ├── Counting Valleys.cpp ├── Mars Exploration.cs ├── Sherlock and Watson.cpp ├── Counting Sort 2.cpp ├── Save The Prisoner.cpp ├── Chocolate Feast.cpp ├── Utopian Tree.cpp ├── Strange Grid.cpp ├── Sansa and XOR.cpp ├── Extra Long Factorials.java ├── Ice Cream Parlor.cpp ├── Encryption.cpp ├── Sock Merchant.cpp ├── Anagram.cpp ├── Restaurant.cpp ├── Summing the N Series.java ├── Arrays Left Rotation.cpp ├── Library Fine.cpp ├── Sequence Equation.cpp ├── Find Point.cpp ├── String Construction.py ├── Lonely Integer.cpp ├── Project-Euler │ ├── 2-Even Fibonacci Numbers.cpp │ ├── 10-Summation of Primes.cpp │ └── 13-Large Sum.java ├── Picking Numbers.go ├── Caesar Cipher.cpp ├── Beautiful Binary String.cs ├── Sherlock and Pairs.cpp ├── Stock Maximize.cpp ├── Game of Thrones 1.cs ├── Cavity Map.cpp ├── Lisa Workbook.cpp ├── Migratory Birds.cpp ├── Maximizing XOR.cpp ├── Closest Numbers.cpp ├── Day of the Programmer.cpp ├── Cats and A Mouse.cpp ├── Minimum Absolute Difference in an Array.cpp ├── Manasa and Stones.cpp ├── Birthday Chocolate.cpp ├── Make it Anagram.cs ├── Hash Tables Ransom Note.go ├── Marcs Cakewalk.cpp ├── Breaking The Records.cpp ├── Is Fibo.cpp └── Electronics Shop.cpp ├── Puzzle └── Sieve of Eratosthenes │ ├── Sieve_of_Eratosthenes.go │ └── My Latest Sieve of Eratosthenes.cpp ├── Codeforces-Solutions ├── A and B and Team Training.cpp └── A and B and Compilation Errors.cpp └── My Simple CPP Template.cpp /Kattis-Solutions/BergMal.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | s = input() 3 | print(s) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Lubbi Laerir.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | s = input() 3 | print(s[0]) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Bitte Ein Bit.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | s = input() 3 | print(s[0]) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Vidsnuningur.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | s = input() 3 | print(s[::-1]) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Kvedja.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | s = input() 3 | print("Kvedja,") 4 | print(s) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/Tolvunarfraedingar Telja.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | x = input() 3 | print(int(x) - 1) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Hipp Hipp.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | for x in range (20): 3 | print("Hipp hipp hurra!") 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Draga Fra.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | a = int(input()) 3 | b = int(input()) 4 | print(a-b) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/Flatbokuveisla.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | b = int(input()) 3 | s = int(input()) 4 | print(b%s) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/Reduplication.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | word = input() 3 | n = int(input()) 4 | print(word*n) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/Til Hamingju.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | print("TIL HAMINGJU MED AFMAELID FORRITUNARKEPPNI FRAMHALDSSKOLANNA!") 3 | -------------------------------------------------------------------------------- /Kattis-Solutions/Pinni Fraendi.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | nd = int(input()) 3 | res ="0." + ("0"*(nd-1)) + "1" 4 | print(res) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/Framtidar FIFA.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | all= int(input()) 3 | x =int(input()) 4 | print(2022 + round(all/x)) 5 | -------------------------------------------------------------------------------- /Kattis-Solutions/A Shortcut to What.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | x =int(input()) 3 | x += 5 4 | x *= 3 5 | x -=10 6 | print(x) 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/A Leid I Bio.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | a = int(input()) 3 | b = int(input()) 4 | c = int(input()) 5 | print(c-a-b) 6 | -------------------------------------------------------------------------------- /Kattis-Solutions/Storafmaeli.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | x = int(input()) 3 | if x%10 == 0: 4 | print("Jebb") 5 | else: 6 | print("Neibb") 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/Peach Powder Polygon.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | n = int(input()) 3 | if n%4 !=0: 4 | print("Yes") 5 | else: 6 | print("No") 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/Takk fyrir mig.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | num = int(input()) 3 | s="" 4 | for x in range(num): 5 | s=input() 6 | print(f"Takk {s}") 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/Fimmtudagstilbod.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | y = int(input()) 3 | if y<= 2020: 4 | print(1000) 5 | else: 6 | print(1000 + ((y-2020) *100)) 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/Hipp Hipp Hurra.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | name = input() 3 | n = int(input()) 4 | 5 | for x in range(n): 6 | print(f"Hipp hipp hurra, {name}!") 7 | -------------------------------------------------------------------------------- /Kattis-Solutions/Ekki Daudi Opna Inni.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | sarra = input().split('|') 3 | sarrb = input().split('|') 4 | print(f"{sarra[0]}{sarrb[0]} {sarra[1]}{sarrb[1]}") 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive-Programming 2 | Just some of my submissions in online competitive programming related sites. 3 | [My Kattis Profile and Stats](https://open.kattis.com/users/surgicalsteel) 4 | -------------------------------------------------------------------------------- /Kattis-Solutions/Pizza Crust.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | float r,c; 5 | cin>>r>>c; 6 | printf("%.6f\n",((r-c)*(r-c)*100)/(r*r)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Kattis-Solutions/Pallatolur.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | a = int(input()) 3 | b = int(input()) 4 | if a<=2 and b>=2: 5 | print("1") 6 | print("2") 7 | else: 8 | print(":(") 9 | -------------------------------------------------------------------------------- /Kattis-Solutions/Buka.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | op = input() 4 | b = int(input()) 5 | 6 | if op=="*": 7 | print(a*b) 8 | else: 9 | print(a+b) 10 | 11 | -------------------------------------------------------------------------------- /Kattis-Solutions/Skocimis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int a,b,c; 5 | scanf("%d %d %d",&a,&b,&c); 6 | printf("%d\n",(max(abs(b-c),abs(a-b))-1)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Kattis-Solutions/Aaah.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string a,b; 6 | cin>>a>>b; 7 | if(a.length()>=b.length()){cout<<"go\n";}else{cout<<"no\n";} 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Shandy.py: -------------------------------------------------------------------------------- 1 | def mini(a,b): 2 | if a 2 | #include 3 | using namespace std; 4 | int main() { 5 | long long inp; 6 | scanf("%lld",&inp); 7 | printf("%.16f",sqrt(inp)*4); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Takkar.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | a= int(input()) 3 | b= int(input()) 4 | if a>b: 5 | print("MAGA!") 6 | elif b>a: 7 | print("FAKE NEWS!") 8 | else: 9 | print("WORLD WAR 3!") 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Stafur.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | vs = {"A","I","U","E","O"} 3 | s = input() 4 | if s in vs: 5 | print("Jebb") 6 | elif s == "Y": 7 | print("Kannski") 8 | else: 9 | print("Neibb") 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Stuck In A Time Loop.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | public class Test 3 | { 4 | public static void Main() 5 | { 6 | int n=int.Parse(Console.ReadLine()); 7 | for(int i=0;i= udd: 7 | print(arr[udd-1]) 8 | else: 9 | print(arr[(udd%num)-1]) 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Take Two Stones.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | func main(){ 5 | var i int 6 | fmt.Scanf("%d", &i) 7 | if i%2==1{ 8 | fmt.Println("Alice") 9 | }else{ 10 | fmt.Println("Bob") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kattis-Solutions/A Second Opinion.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | ns = int(input()) 3 | modh = ns % 3600 4 | nh = round((ns - modh) / 3600) 5 | modm = modh % 60 6 | nm = round((modh - modm) / 60) 7 | ns = modm 8 | print(f"{nh} : {nm} : {ns}") 9 | -------------------------------------------------------------------------------- /Kattis-Solutions/Call for Problems.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | counter = 0 3 | temp = 0 4 | np = int(input()) 5 | for x in range(np): 6 | temp = int(input()) 7 | if temp%2 == 1: 8 | counter += 1 9 | print(counter) 10 | -------------------------------------------------------------------------------- /Kattis-Solutions/Multiplications.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | tot = 1 3 | n = int(input()) 4 | m = 1000000007 5 | temp = 0 6 | for x in range(n): 7 | temp = int(input()) % m 8 | tot = tot * temp 9 | 10 | print(tot%m) 11 | -------------------------------------------------------------------------------- /Kattis-Solutions/Three in a Row.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__" : 2 | arr = [] 3 | 4 | for x in range(1002): 5 | arr.append((x+1) * (x+2) * (x+3)) 6 | 7 | n = int(input()) 8 | 9 | newarr = [x for x in arr if x < n] 10 | print(len(newarr)) 11 | -------------------------------------------------------------------------------- /Kattis-Solutions/Bishops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | while(cin>>n) 7 | { 8 | if(n==1){cout<<"1\n";} 9 | else if(n>1) 10 | {cout< 2 | using namespace std; 3 | int main() { 4 | int tc; 5 | string s; 6 | scanf("%d",&tc); 7 | for(int i=0;i>s; 10 | printf("%d\n",s.length()); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Hackerrank/A Very Big Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | long long a,sum=0; 9 | cin>>n; 10 | for(int i=0;i>a; 13 | sum+=a; 14 | } 15 | cout< 2 | using namespace std; 3 | #define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286 4 | int main() { 5 | double inp; 6 | cin>>inp; 7 | printf("%.6f\n",inp*inp*PI); 8 | printf("%.6f\n",2*inp*inp); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Kattis-Solutions/A Different Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long absolutey(long long x) 4 | { 5 | if(x<0){return x*-1;} 6 | else{return x;} 7 | } 8 | int main() { 9 | long long a,b; 10 | while(cin>>a>>b) 11 | { 12 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int n,a=1,b=0,iter=0,temp; 6 | cin>>n; 7 | while(iter 2 | using namespace std; 3 | 4 | int main() { 5 | int nt,m,nm=0,ctr=0,temp; 6 | cin>>nt>>m; 7 | for(int i=0;i>temp; 10 | if((nm+temp)<=m){nm+=temp;ctr++;}else{break;} 11 | } 12 | cout< maxf: 9 | name = sarr[0] 10 | maxf = int(sarr[1]) 11 | 12 | print(name) 13 | -------------------------------------------------------------------------------- /Kattis-Solutions/Canadians Eh.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Canadians_Eh 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string s = Console.ReadLine(); 10 | Console.WriteLine(s.EndsWith("eh?") ? "Canadian!" : "Imposter!"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kattis-Solutions/Soylent.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | func main(){ 5 | // your code goes here 6 | var it,t,r int; 7 | fmt.Scanf("%d",&it); 8 | for x:=0;x0: 10 | cv -= 1 11 | 12 | print(cv) 13 | -------------------------------------------------------------------------------- /Kattis-Solutions/Basketball One-on-One.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Basketball_One_on_One 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string s = Console.ReadLine(); 10 | Console.WriteLine(s.Substring(s.Length - 2, 1)); 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Hackerrank/Minimum Draws.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int tc,temp; 11 | scanf("%d",&tc); 12 | for(int i=0;i 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int temp; 8 | vector v; 9 | for(int i=0;i<4;i++) 10 | {cin>>temp;v.pb(temp);} 11 | sort(v.begin(),v.end()); 12 | cout< y? x : y; 11 | } 12 | 13 | // Compute x - y 14 | int difference(int x, int y){ 15 | return x-y; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Kattis-Solutions/Different Distances.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | float xa,ya,xb,yb,p,res; 5 | while(cin>>xa>>ya>>xb>>yb>>p) 6 | { 7 | res=pow((pow(abs(xa-xb),p)+pow(abs(ya-yb),p)),1/p); 8 | //printf("%.1f %.1f %.1f %.1f %.1f\n",xa,ya,xb,yb,p); 9 | printf("%.10f\n",res); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Kattis-Solutions/Maddelande.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | sarr = input().split() 3 | nline = int(sarr[0]) 4 | slen = int(sarr[1]) 5 | s = "" 6 | res = "" 7 | for x in range(nline): 8 | s = input() 9 | for x in range(slen): 10 | if s[x] != ".": 11 | res += s[x] 12 | 13 | print(res) 14 | -------------------------------------------------------------------------------- /Kattis-Solutions/Spritt.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | sarr = input().split(' ') 3 | nq = int(sarr[0]) 4 | tot = int(sarr[1]) 5 | temp = 0 6 | tt = 0 7 | for x in range(nq): 8 | temp = int(input()) 9 | tt += temp 10 | 11 | if tt > tot: 12 | print("Neibb") 13 | else: 14 | print("Jebb") 15 | -------------------------------------------------------------------------------- /Kattis-Solutions/Decimal Deletion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Decimal_Deletion 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | double di = double.Parse(Console.ReadLine()); 10 | double res = Math.Round(di); 11 | Console.WriteLine(res); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kattis-Solutions/Triple Sevens.py: -------------------------------------------------------------------------------- 1 | if __name__=="__main__": 2 | sza = int(input()) 3 | a = [x for x in input().split() if x =="7"] 4 | b = [x for x in input().split() if x =="7"] 5 | c = [x for x in input().split() if x =="7"] 6 | 7 | if len(a) >0 and len(b) >0 and len(c) >0: 8 | print("777") 9 | else: 10 | print("0") 11 | -------------------------------------------------------------------------------- /Kattis-Solutions/Job Expenses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | long long xtot=0,tmp; 9 | cin>>n; 10 | for(int i=0;i>tmp; 12 | if(tmp<0){ 13 | xtot += (tmp * -1); 14 | } 15 | } 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a; 8 | cin>>a; 9 | for(int j=0;j=a-1){cout<<"#";} 14 | else{cout<<" ";} 15 | } 16 | cout<<"\n"; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Kattis-Solutions/Revision Control.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | num = int(input()) 3 | d = dict() 4 | ares = [] 5 | arin = input().split(" ") 6 | for x in range(num): 7 | if arin[x] in d.keys(): 8 | ares.append("0") 9 | else: 10 | d[arin[x]] = 1 11 | ares.append("1") 12 | print(" ".join(ares)) 13 | -------------------------------------------------------------------------------- /Kattis-Solutions/Estimating the Area of a Circle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define PI 3.141592654 4 | int main() { 5 | float r,m,c,resa,resb; 6 | cin>>r>>m>>c; 7 | while(r!=0&&m!=0&&c!=0) 8 | { 9 | resa=PI*r*r; 10 | resb=4*c/m*r*r; 11 | cout<>r>>m>>c; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Kattis-Solutions/Oddities.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int tc,x; 7 | cin>>tc; 8 | for(int i=0;i>x; 11 | if(x%2==0){cout< 2 | using namespace std; 3 | int main() { 4 | int n,t,ma; 5 | scanf("%d",&n); 6 | int h[101]; 7 | memset(h,0,sizeof(h)); 8 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | int main() { 5 | char str[100]; 6 | int tc; 7 | scanf("%d",&tc); 8 | for(int i=0;i>str; 11 | if(next_permutation(str,str+strlen(str))) 12 | {cout<= 0 && x%5 < 3 { 16 | fmt.Println(x) 17 | } else { 18 | if (x + (5 - (x % 5))) >= 40 { 19 | x += (5 - (x % 5)) 20 | } 21 | fmt.Println(x) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/Champernowne Verification.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | arr = [] 3 | for x in range(11): 4 | if x==0: 5 | arr.append(str(x+1)) 6 | else: 7 | arr.append(arr[x-1]+str(x+1)) 8 | 9 | #print(arr) 10 | 11 | res = -1 12 | s = input() 13 | for x in range(11): 14 | if s == arr[x] : 15 | res = x+1 16 | 17 | print(res) 18 | -------------------------------------------------------------------------------- /Kattis-Solutions/Detailed Differences.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int tc; 5 | string a,b,build; 6 | scanf("%d",&tc); 7 | while(tc--) 8 | { 9 | build=""; 10 | cin>>a>>b; 11 | for(int i=0;i 2 | using namespace std; 3 | int main() { 4 | int n,k,b,tb=0; 5 | scanf("%d %d",&n,&k); 6 | int arr[n]; 7 | for(int i=0;i12 && b <=12){print("EU");}else if(a<=12 && b>12){print("US");} 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Kattis-Solutions/Jack O Lantern Juxtaposition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Jack_O_Lantern_Juxtaposition 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] sarr = Console.ReadLine().Split(" "); 10 | int tot = int.Parse(sarr[0]) * int.Parse(sarr[1]) * int.Parse(sarr[2]); 11 | Console.WriteLine("{0}", tot); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kattis-Solutions/Trapizza.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | if __name__ == "__main__": 4 | d = float(input()) 5 | r = float(d/2) 6 | sa = float(input()) 7 | sb = float(input()) 8 | h = float(input()) 9 | lm = float(math.pi * r * r) 10 | lt = float((sa+sb)*h/2) 11 | 12 | if lm>lt: 13 | print("Mahjong!") 14 | elif lt > lm: 15 | print("Trapizza!") 16 | else: 17 | print("Jafn storar!") 18 | -------------------------------------------------------------------------------- /Hackerrank/Handshake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int tc; 8 | cin>>tc; 9 | int num[tc]; 10 | for(int i=0;i>num[i]; 13 | int x=num[i]; 14 | if(x==1){num[i]=0;} 15 | else{num[i]=(x*(x-1))/2;} 16 | } 17 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | int d; 6 | long long int n=0,cdl=0; 7 | cin>>d; 8 | if(d==1){n=2;} 9 | else{ 10 | cdl=2; 11 | n=cdl; 12 | for(int i=1;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int main() { 11 | // your code goes here 12 | int na,ni; 13 | cin>>na>>ni; 14 | cout<<((ni-1)*na)+1<<"\n"; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Kattis-Solutions/Greetings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Greetings 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string g = Console.ReadLine(); 10 | int x = (g.Length - 2) * 2; 11 | string n = "h"; 12 | for(int i = 0; i < x; i++) { n += "e"; } 13 | n += "y"; 14 | Console.WriteLine(n); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Kattis-Solutions/Mixed Fractions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a,b; 6 | cin>>a>>b; 7 | while(a!=0&&b!=0) 8 | { 9 | if(a>a>>b; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Kattis-Solutions/GCD.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GCD 4 | { 5 | class Program 6 | { 7 | static int gcd(int a, int b) 8 | { 9 | return b == 0 ? a : gcd(b, a % b); 10 | } 11 | static void Main(string[] args) 12 | { 13 | string[] sarr = Console.ReadLine().Split(' '); 14 | Console.WriteLine(gcd(int.Parse(sarr[0]), int.Parse(sarr[1]))); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Kattis-Solutions/Ladder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.1415926535897932384626433832795 4 | using namespace std; 5 | int solve(int h,int a) 6 | { 7 | double res=(double) (h / (sin((double) (a*PI)/180))); 8 | return (int) ceil(res); 9 | } 10 | int main() { 11 | // your code goes here 12 | int height,angle; 13 | cin>>height>>angle; 14 | cout<= 0; i--) { Console.WriteLine(arr[i]); } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kattis-Solutions/Seven Wonders.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | string s; 5 | cin>>s; 6 | int nt=0,nc=0,ng=0; 7 | long long int tot; 8 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | long long temp; 6 | int tc,n,tot=0; 7 | cin>>tc; 8 | for(int i=0;i>n; 11 | tot=0; 12 | for(int j=0;j>temp; 15 | tot+=temp%n; 16 | } 17 | if(tot%n==0){cout<<"YES\n";}else{cout<<"NO\n";} 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Kattis-Solutions/Sort Two Numbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sort_Two_Numbers 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] sarr = Console.ReadLine().Split(' '); 10 | if (int.Parse(sarr[0]) > int.Parse(sarr[1])) { Console.WriteLine("{0} {1}", sarr[1], sarr[0]); } 11 | else { Console.WriteLine(string.Join(" ", sarr)); } 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kattis-Solutions/Hailstone Sequence.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | start = int(input()) 3 | 4 | sn = set() 5 | oneFound = start == 1 6 | next = start 7 | sn.add(start) 8 | 9 | 10 | while not oneFound: 11 | if next%2 == 0: 12 | next = next/2 13 | else: 14 | next = (next *3) + 1 15 | sn.add(next) 16 | 17 | if next == 1: 18 | oneFound = True 19 | 20 | print(len(sn)) 21 | -------------------------------------------------------------------------------- /Hackerrank/Birthday Cake Candles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define psb push_back 4 | 5 | int main() { 6 | int nc,t,mx=-1999999999,res=0; 7 | vector v; 8 | cin>>nc; 9 | for(int i=0;i>t; 11 | mx=max(t,mx); 12 | v.psb(t); 13 | } 14 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int main() { 8 | int tc,temp; 9 | vector v; 10 | scanf("%d",&tc); 11 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,t,m,r; 8 | vector v; 9 | scanf("%d",&n); 10 | for(int i=0;i 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int sa,se,pa,po,na,no,t,ca=0,co=0; 6 | cin>>sa>>se>>pa>>po>>na>>no; 7 | for(int i=0;i>t; 10 | if(((pa+t)>=sa)&&((pa+t)<=se)){ca++;} 11 | } 12 | for(int i=0;i>t; 15 | if(((po+t)>=sa)&&((po+t)<=se)){co++;} 16 | } 17 | cout< 2 | using namespace std; 3 | int main(){ 4 | long long int x=0,n; 5 | string s; 6 | cin>>s; 7 | cin>>n; 8 | for(int it=0;it 2 | using namespace std; 3 | 4 | int main() { 5 | int tc,r,c,temp; 6 | scanf("%d",&tc); 7 | for(int it=0;it>img[ir];} 13 | cout<<"Test "< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int h,m,less; 7 | cin>>h>>m; 8 | if(h==0&&m<45) 9 | { 10 | h=23; 11 | less=45-m; 12 | m=60-less; 13 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int ax,bx,cx,ay,by,cy,dx,dy; 7 | scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&cx,&cy); 8 | if(ax!=bx&&ax!=cx){dx=ax;} 9 | else if(bx!=ax&&bx!=cx){dx=bx;} 10 | else if(cx!=ax&&cx!=bx){dx=cx;} 11 | if(ay!=by&&ay!=cy){dy=ay;} 12 | else if(by!=ay&&by!=cy){dy=by;} 13 | else if(cy!=ay&&cy!=by){dy=cy;} 14 | printf("%d %d\n",dx,dy); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Kattis-Solutions/Symmetric Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pb push_back 3 | using namespace std; 4 | int main() { 5 | 6 | int tc,ctrset=1; 7 | cin>>tc; 8 | string tmp; 9 | while(tc!=0) 10 | { 11 | vector vs; 12 | for(int i=0;i>tmp;vs.pb(tmp);} 13 | cout<<"SET "<=0;i--){if(i%2!=0){cout<>tc; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Hackerrank/Intro to Tutorial Challenges.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int n,search,res; 12 | cin>>search>>n; 13 | int arr[n]; 14 | for(int i=0;i>arr[i]; 17 | if(arr[i]==search){res=i;} 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int e,m; // e : 0-364 & m : 0-686 6 | int cs=1; 7 | while(cin>>e>>m) 8 | { 9 | if(m==0&&e==0){printf("Case %d: 0\n",cs);} 10 | else 11 | { 12 | bool breaker=false; 13 | int step=0; 14 | while(!breaker) 15 | { 16 | m=(m+1)%687; 17 | e=(e+1)%365; 18 | step++; 19 | if(m==0&&e==0){breaker=true;} 20 | } 21 | printf("Case %d: %d\n",cs,step); 22 | } 23 | cs++; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hackerrank/Flipping Bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int tc; 12 | cin>>tc; 13 | long long res[tc],temp; 14 | for(int i=0;i>temp; 17 | res[i]=4294967295-temp; 18 | } 19 | for(int i=0;i 2 | using namespace std; 3 | int main() { 4 | string forb; 5 | int tc,temp,nm,h,m; 6 | cin>>tc; 7 | while(tc--) 8 | { 9 | cin>>forb>>nm>>h>>m; 10 | if(forb=="F")//forward 11 | { 12 | m+=nm; 13 | h+=((m-(m%60))/60); 14 | m=m%60; 15 | h=h%24; 16 | } 17 | else//backward 18 | { 19 | while(nm>m) 20 | { 21 | m+=60; 22 | h--; 23 | } 24 | m=m-nm; 25 | if(h<0){h+=24;} 26 | } 27 | printf("%d %d\n",h,m); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Kattis-Solutions/No Duplicates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | int main() { 9 | map::iterator it; 10 | string s; 11 | map m; 12 | bool isex=false; 13 | while(cin>>s){ 14 | it=m.find(s); 15 | if(it != m.end()){ 16 | isex=true; 17 | } 18 | m[s]=1; 19 | } 20 | if (isex){cout<<"no\n";}else{cout<<"yes\n";} 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Hackerrank/Minimum Distances.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n,t,sz,mi=1000000; 5 | scanf("%d",&n); 6 | int hlast[100000]; 7 | memset(hlast,-1,sizeof(hlast)); 8 | for(int i=0;i 2 | using namespace std; 3 | string tostr(int x) 4 | { 5 | ostringstream ss; 6 | ss<>tot>>skip; 12 | string s = ""; 13 | for(int i=1;i<=tot;i++) 14 | { 15 | cin>>temp; 16 | if((i%skip)==0){ 17 | if(s.length()==0){s+=tostr(temp);} 18 | else{s+= (" "+tostr(temp));} 19 | } 20 | } 21 | 22 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int main() { 8 | int tc,temp,nc; 9 | scanf("%d",&tc); 10 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int n,temp; 12 | cin>>n; 13 | int arr[100]; 14 | for(int i=0;i<100;i++){arr[i]=0;} 15 | for(int i=0;i>temp; 18 | arr[temp]++; 19 | } 20 | for(int i=0;i<100;i++) 21 | {cout< 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int r,n,temp; 8 | cin>>r>>n; 9 | int arr[r]; 10 | for(int i=0;i>temp; 15 | arr[temp-1]=temp; 16 | } 17 | if(r==n){cout<<"too late\n";} 18 | int i=0; 19 | while(i 2 | using namespace std; 3 | int main() { 4 | int n,p,temp; 5 | scanf("%d %d",&n,&p); 6 | int vs[n]; 7 | for(int i=0;i 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int a,b,c; 6 | vector v; 7 | cin>>a>>b>>c; 8 | v.psb(a); 9 | v.psb(b); 10 | v.psb(c); 11 | sort(v.begin(),v.end()); 12 | if(abs(v[0]-v[1])>abs(v[1]-v[2])) 13 | { 14 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t,n,k; 8 | cin>>t; 9 | string ans[t]; 10 | for(int i=0;i>n>>k; 13 | int arrivaltime[n],counter=0; 14 | for(int x=0;x>arrivaltime[x]; 17 | if(arrivaltime[x]<=0){counter++;} 18 | } 19 | if(counter>=k){ans[i]="NO";}else{ans[i]="YES";} 20 | } 21 | for(int i=0;i d { 21 | fmt.Println("NE") 22 | } else { 23 | fmt.Println("DA") 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kattis-Solutions/Backspace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define psb push_back 4 | int main() { 5 | string s; 6 | cin>>s; 7 | if(s.length()==1){cout< ss; 11 | for(int i=0;i vs; 17 | while(!ss.empty()) 18 | { 19 | vs.psb(ss.top()); 20 | ss.pop(); 21 | } 22 | for(int i=vs.size()-1;i>=0;--i){cout<= 2 && hc - hs >= 2) { Console.WriteLine("1"); } else { Console.WriteLine("0"); } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kattis-Solutions/Quadrant Selection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int main() { 11 | // your code goes here 12 | int x,y; 13 | cin>>x>>y; 14 | if(x>0&&y>0){cout<<"1\n";} 15 | else if(x>0&&y<0){cout<<"4\n";} 16 | else if(x<0&&y<0){cout<<"3\n";} 17 | else if(x<0&&y>0){cout<<"2\n";} 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Kattis-Solutions/Chanukah Challenge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Chanukah_Challenge 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int n = int.Parse(Console.ReadLine()); 10 | for(int i = 0; i < n; i++) 11 | { 12 | String[] arr = Console.ReadLine().Split(" "); 13 | int num = int.Parse(arr[1]); 14 | int res = ((num + 1) * num) / 2 + num; 15 | Console.WriteLine("{0} {1}", arr[0], res); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Kattis-Solutions/Prsteni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define psb push_back 3 | using namespace std; 4 | int gcd(int a,int b) 5 | { 6 | bool found=false; 7 | int i=min(a,b); 8 | while(!found&&i>=1) 9 | { 10 | if(a%i==0&&b%i==0){found=true;} 11 | else{i--;} 12 | } 13 | return i; 14 | } 15 | int main() { 16 | int n,temp,g; 17 | vector v; 18 | scanf("%d",&n); 19 | for(int i=0;i 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int n,k,t,ctr=0; 6 | vector vi; 7 | scanf("%d %d",&n,&k); 8 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int t; 10 | unsigned long long ho,htb,htw,b,w,x,y,z;//htw default w 11 | scanf("%d",&t); 12 | for(int a0 = 0; a0 < t; a0++){ 13 | scanf("%lld %lld",&b,&w); 14 | scanf("%lld %lld %lld",&x,&y,&z); 15 | ho=(b*x)+(w*y); 16 | htw=((w+b)*y)+(b*z); 17 | htb=((w+b)*x)+(w*z); 18 | printf("%lld\n",min(ho,min(htw,htb))); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Kattis-Solutions/Ostgotska.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | func main() { 11 | reader := bufio.NewReader(os.Stdin) 12 | s, _ := reader.ReadString('\n') 13 | ss := strings.Split(s, " ") 14 | tot := len(ss) 15 | ctr := int(0) 16 | for _, v := range ss { 17 | if strings.Contains(v, "ae") { 18 | ctr++ 19 | } 20 | } 21 | p := float64(0) 22 | p = (float64(ctr) / float64(tot)) * 100 23 | if p >= 40 { 24 | fmt.Println("dae ae ju traeligt va") 25 | } else { 26 | fmt.Println("haer talar vi rikssvenska") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Hackerrank/Sherlock and The Beast.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int tc,a,b; 5 | string ba,bb; 6 | scanf("%d",&tc); 7 | while(tc--) 8 | { 9 | scanf("%d",&a); 10 | b=a; 11 | while(b%3!=0) 12 | {b-=5;} 13 | if(b<0){printf("-1\n");} 14 | else 15 | { 16 | ba=""; 17 | bb=""; 18 | for(int i=0;i 2 | using namespace std; 3 | int getnext(int n) 4 | { 5 | if(n<8){return n+1;} 6 | else{return 1;} 7 | } 8 | int main() { 9 | // your code goes here 10 | int init,num,timetot=210,dur; 11 | string stat; 12 | cin>>init>>num; 13 | for(int i=0;i>dur>>stat; 16 | if(timetot-dur>0&&stat=="T"){init=getnext(init);timetot-=dur;} 17 | else if(timetot-dur<=0){break;} 18 | else if(stat=="N"||stat=="P"){timetot-=dur;} 19 | } 20 | cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int main() { 11 | // your code goes here 12 | float D,V; 13 | cin>>D>>V; 14 | while(D!=0&&V!=0) 15 | { 16 | float res=pow((6*((PI*pow(D,3)/4)-V)/PI)-(pow(D,3)/2),1.0/3); 17 | printf("%.10f\n",res); 18 | cin>>D>>V; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank/Diagonal Difference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,suma=0,sumb=0; 8 | cin>>n; 9 | int matriks[n][n]; 10 | for(int j=0;j>matriks[j][i]; 15 | } 16 | } 17 | for(int j=0;j 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | int n; 10 | int t; 11 | cin >> n >> t; 12 | vector width(n); 13 | for(int width_i = 0;width_i < n;width_i++){ 14 | cin >> width[width_i]; 15 | } 16 | for(int a0 = 0; a0 < t; a0++){ 17 | int a; 18 | int b; 19 | cin >> a >> b; 20 | int mini=3; 21 | for(int i=a;i<=b;i++){mini=min(width[i],mini);} 22 | printf("%d\n",mini); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Kattis-Solutions/Shattered Cake.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Shattered_Cake 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int w = int.Parse(Console.ReadLine()); 10 | int n = int.Parse(Console.ReadLine()); 11 | int tempArea = 0; 12 | for(int i = 0; i < n; i++) 13 | { 14 | String[] arr = Console.ReadLine().Split(" "); 15 | tempArea += (int.Parse(arr[0]) * int.Parse(arr[1])); 16 | } 17 | Console.WriteLine(tempArea / w); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kattis-Solutions/Tok Tik.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | nq = int(input()) 3 | d = dict() 4 | sarr = [] 5 | tempc = 0 6 | tmaxi = 0 7 | tname = "" 8 | for x in range(nq): 9 | sarr = input().split(' ') 10 | if sarr[0] in d: 11 | tempc = d[sarr[0]] 12 | tempc += int(sarr[1]) 13 | 14 | else: 15 | tempc = int(sarr[1]) 16 | 17 | d[sarr[0]] = tempc 18 | 19 | for key in d.keys(): 20 | if d[key] > tmaxi : 21 | tmaxi = d[key] 22 | tname = key 23 | 24 | print(tname) 25 | 26 | -------------------------------------------------------------------------------- /Kattis-Solutions/Cryptographers Conundrum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string low(string inp) 4 | { 5 | string res; 6 | locale loc; 7 | for(string::size_type i=0;i>inp; 14 | inp=low(inp); 15 | int tot=0; 16 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | 9 | int main() { 10 | int step,lv=0,nov=0; 11 | string sq; 12 | cin>>step>>sq; 13 | for(int i=0;i 2 | #include 3 | #define pub push_back 4 | #define pob pop_back 5 | using namespace std; 6 | int main() { 7 | int sz,k,nq,q,temp; 8 | cin>>sz>>k>>nq; 9 | vector v; 10 | for(int i=0;i>q; 24 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int n,temp; 12 | cin>>n; 13 | int arr[100]; 14 | for(int i=0;i<100;i++){arr[i]=0;} 15 | for(int i=0;i>temp; 18 | arr[temp]++; 19 | } 20 | for(int i=0;i<100;i++) 21 | { 22 | if(arr[i]>0) 23 | {for(int x=0;x 2 | using namespace std; 3 | int solve(int p, int m, int s) 4 | { 5 | m%=p; 6 | if(m==1&&s>1){return s;} 7 | if(s==1&&m>0){return m;} 8 | else if(m==0) 9 | { 10 | if(s==1){return p;} 11 | else return m+1; 12 | } 13 | else { 14 | m--; 15 | if((m+s)>p){return abs(p-(m+s));} 16 | else{return m+s;} 17 | } 18 | } 19 | int main() { 20 | int tc,p,m,s; 21 | scanf("%d",&tc); 22 | while(tc--) 23 | { 24 | scanf("%d %d %d",&p,&m,&s); 25 | printf("%d\n",solve(p,m,s)); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Kattis-Solutions/GCVWR.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GCVWR 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int g, t, n; 10 | string[] sarr; 11 | sarr = Console.ReadLine().Split(' '); 12 | g = int.Parse(sarr[0]); 13 | t = int.Parse(sarr[1]); 14 | sarr = Console.ReadLine().Split(' '); 15 | int tot = 0; 16 | for(int i = 0; i < sarr.Length; i++) { tot += int.Parse(sarr[i]); } 17 | int maxi = (90 * (g - t) / 100) - tot; 18 | Console.WriteLine(maxi); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kattis-Solutions/Undead or Alive.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | func main() { 11 | var s string 12 | reader := bufio.NewReader(os.Stdin) 13 | s, _ = reader.ReadString('\n') 14 | s = strings.Trim(s, " ") 15 | if strings.Contains(s, ":)") { 16 | if strings.Contains(s, ":(") { 17 | fmt.Println("double agent") 18 | } else { 19 | fmt.Println("alive") 20 | } 21 | } else if strings.Contains(s, ":(") { 22 | fmt.Println("undead") 23 | } else { 24 | fmt.Println("machine") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Hackerrank/Chocolate Feast.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 5 | int t,n,c,m; 6 | cin>>t; 7 | while(t>0){ 8 | cin>>n>>c>>m; 9 | int x=(n-(n%c))/c; 10 | int y=x; 11 | int sisa=0; 12 | if(y>=m) 13 | { 14 | while (y>=m) 15 | { 16 | sisa=y%m; 17 | y=(y-sisa)/m; 18 | x+=y; 19 | y+=sisa; 20 | } 21 | } 22 | cout<=0 : 11 | arr[x-1] = "-" 12 | 13 | newarr = [] 14 | 15 | for x in range(szin): 16 | if arr[x] != "Present!" and arr[x] != "-": 17 | newarr.append(arr[x]) 18 | 19 | if len(newarr) == 0: 20 | print("No Absences") 21 | else : 22 | for x in range (len(newarr)): 23 | print(newarr[x]) 24 | 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/Howl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Howl 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | String s = Console.ReadLine(); 10 | if (s.Substring(s.Length - 1, 1) == "W") 11 | { 12 | s += "H"; 13 | } 14 | else if (s.Substring(s.Length - 1, 1) == "O") 15 | { 16 | s += "W"; 17 | } 18 | else if (s.Substring(s.Length - 1, 1) == "H") 19 | { 20 | s += "O"; 21 | } 22 | Console.WriteLine(s); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kattis-Solutions/Vauvau.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int ba,ra,bb,rb;//bark and rest 4 | string solve(int t) 5 | { 6 | int ctrdog=0; 7 | if(t%(ba+ra)<=ba&&t%(ba+ra)!=0){ctrdog++;} 8 | if(t%(bb+rb)<=bb&&t%(bb+rb)!=0){ctrdog++;} 9 | if(ctrdog==0){return "none\n";} 10 | else if(ctrdog==1){return "one\n";} 11 | else if(ctrdog==2){return "both\n";} 12 | else{return " ";} 13 | } 14 | int main() { 15 | 16 | int s,d,t; 17 | cin>>ba>>ra>>bb>>rb>>s>>d>>t; 18 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int height=1,testcases; 8 | cin>>testcases; 9 | int arresult[testcases],tampung[testcases]; 10 | for(int i=0;i>tampung[i];} 12 | for(int i=0;i mod = new List(); 14 | int temp; 15 | for(int i = 0; i < 10; i++) 16 | { 17 | temp = int.Parse(Console.ReadLine()); 18 | mod.Add(temp % 42); 19 | } 20 | List ctr = mod.Distinct().ToList(); 21 | Console.WriteLine(ctr.Count); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/R2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>a>>b; 27 | cout<<(b*2)-a<<"\n"; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Kattis-Solutions/Sticky Keys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sticky_Keys 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string sin = Console.ReadLine(); 10 | string cc = sin.Substring(0,1); 11 | string vs; 12 | string res = ""; 13 | for(int i = 0; i < sin.Length; i++) 14 | { 15 | vs = sin.Substring(i, 1); 16 | if(vs != cc) { res += cc; cc = vs; } 17 | if ((i + 1) == sin.Length) { res += cc; } 18 | } 19 | Console.WriteLine(res); 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Hackerrank/Strange Grid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | long long findbaserow(long long row) 10 | { 11 | if((row-1)%2==0){return (row-1)*10/2;} 12 | else{return ((row-2)*10/2)+1;} 13 | } 14 | long long findnum(long long col,long long baserow) 15 | { 16 | if(col>1) 17 | {return baserow+(2*(col-1));} 18 | else{return baserow;} 19 | } 20 | int main() { 21 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 22 | long long r,c; 23 | cin>>r>>c; 24 | cout< 0) { Console.WriteLine("still running"); return; } 15 | 16 | long tot = 0; 17 | for(int i = 0; i < n-1; i+=2) 18 | {tot += (long)Math.Abs(arr[i] - arr[i + 1]);} 19 | 20 | Console.WriteLine("{0}", tot); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kattis-Solutions/Keys Phone Wallet.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | sz = int(input()) 3 | isKey = False 4 | isPhone = False 5 | isWallet = False 6 | for x in range(sz): 7 | temp = input() 8 | if temp == "keys" : 9 | isKey =True 10 | elif temp == "phone" : 11 | isPhone = True 12 | elif temp == "wallet" : 13 | isWallet = True 14 | 15 | if isKey and isPhone and isWallet : 16 | print("ready") 17 | else : 18 | if not(isKey): 19 | print("keys") 20 | if not(isPhone): 21 | print("phone") 22 | if not(isWallet): 23 | print("wallet") 24 | -------------------------------------------------------------------------------- /Kattis-Solutions/Trik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string s; 6 | cin>>s; 7 | int init=1; 8 | for(int x=0;x= p) 18 | { 19 | tmp = (tot / p) + (tot % p); 20 | n += tot / p; 21 | tot = tmp; 22 | } 23 | Console.WriteLine(n); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kattis-Solutions/Triple Texting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TripleTexting 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string s = Console.ReadLine(); 10 | int len = s.Length; 11 | string a, b, c; 12 | a = s.Substring(0, len / 3); 13 | b = s.Substring(len / 3, len / 3); 14 | c = s.Substring(len - (len / 3), len / 3); 15 | if (a == b || a == c) 16 | { 17 | Console.WriteLine(a); 18 | }else if(b == c) 19 | { 20 | Console.WriteLine(c); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Hackerrank/Sansa and XOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define psb push_back 4 | int main() { 5 | int tc,sz,ptr; 6 | long long int temp,x; 7 | scanf("%d",&tc); 8 | while(tc--) 9 | { 10 | scanf("%d",&sz); 11 | vector v; 12 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | 11 | int main() { 12 | // your code goes here 13 | int n,cwoa,cwa,ca; 14 | cin>>n; 15 | for(int i=0;i>cwoa>>cwa>>ca; 17 | if(ca+cwoa==cwa){ 18 | cout<<"does not matter\n"; 19 | }else if (ca+cwoa 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int tc,sz,temp,n; 6 | long long int res; 7 | scanf("%d",&tc); 8 | n=tc; 9 | while(tc--) 10 | { 11 | res=0; 12 | scanf("%d",&sz); 13 | vector va,vb; 14 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int main() { 8 | int tc,m,n,temp; 9 | scanf("%d",&tc); 10 | for(int i=0;i v; 13 | cin>>m>>n; 14 | for(int x=0;x>temp; 17 | v.push_back(temp); 18 | } 19 | for(int x=0;x 2 | using namespace std; 3 | char toCharSingle(string x)//single substring as input. Converts single substring to single char 4 | { 5 | char a[1]; 6 | strncpy(a,x.c_str(),sizeof(a)); 7 | return a[0]; 8 | } 9 | int main() { 10 | int hash[26]; 11 | for(int i=0;i<26;i++){hash[i]=0;} 12 | string s; 13 | cin>>s; 14 | int l=s.length(); 15 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>nit; 27 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main(){ 5 | string s; 6 | cin >> s; 7 | int row=(int) floor(sqrt((double) s.length())),col=(int) ceil(sqrt((double) s.length())),ctr=0; 8 | if(row*col 2 | using namespace std; 3 | #define psb push_back 4 | int main() { 5 | int n,x,c=0; 6 | scanf("%d",&n); 7 | vector idx,ctr; 8 | vector::iterator iter; 9 | int ar[n]; 10 | while(n--) 11 | { 12 | scanf("%d",&ar[c]); 13 | iter = find(idx.begin(),idx.end(),ar[c]); 14 | if(iter==idx.end()) 15 | { 16 | idx.psb(ar[c]); 17 | ctr.psb(1); 18 | } 19 | else 20 | {ctr[distance(idx.begin(),iter)]++;} 21 | } 22 | int tot =0; 23 | for(int it=0;it d = new Dictionary(); 11 | bool flag = true; 12 | string x; 13 | for (int i = 0; i < s.Length; i++) 14 | { 15 | x = s.Substring(i, 1); 16 | if (d.ContainsKey(x)) { flag = false; break; } else { d.Add(x, 1); } 17 | } 18 | if (flag) { Console.WriteLine("1"); } else { Console.WriteLine("0"); } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kattis-Solutions/Synchronizing List.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int tc; 8 | cin>>tc; 9 | while(tc!=0) 10 | { 11 | vector la,lb,lao; 12 | int temp; 13 | for(int i=0;i<2*tc;i++) 14 | { 15 | cin>>temp; 16 | if(i::iterator iter; 22 | for(int i=0;i>tc; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Kattis-Solutions/Class Field Trip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Class_Field_Trip 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | string sa = Console.ReadLine(); 11 | string sb = Console.ReadLine(); 12 | List sf = new List(); 13 | string s = ""; 14 | for(int i = 0; i < sa.Length; i++) { sf.Add(sa.Substring(i, 1)); } 15 | for (int i = 0; i < sb.Length; i++) { sf.Add(sb.Substring(i, 1)); } 16 | sf.Sort(); 17 | for (int i = 0; i < sf.Count; i++) { s += (sf[i]); } 18 | Console.WriteLine(s); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Hackerrank/Anagram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define psb push_back 4 | int main() { 5 | int tc; 6 | scanf("%d",&tc); 7 | while(tc--) 8 | { 9 | char inp[10000]; 10 | scanf("%s",&inp); 11 | if(strlen(inp)%2!=0){printf("-1\n");} 12 | else 13 | { 14 | int half=strlen(inp)/2; 15 | int hasha[26],hashb[26]; 16 | for(int i=0;i<26;++i) 17 | { 18 | hasha[i]=0; 19 | hashb[i]=0; 20 | } 21 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | int findgcd(int a,int b) 8 | { 9 | int maxi=0; 10 | for(int i=1;i<=min(a,b);i++) 11 | { 12 | if(a%i==0&&b%i==0) 13 | {maxi=i;} 14 | } 15 | return maxi; 16 | } 17 | //hackerrank-->math-->fundamental-->restaurant 18 | int main() { 19 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 20 | int tc,i=0,l,b,res; 21 | cin>>tc; 22 | while(i>l>>b; 25 | res=(l*b)/(findgcd(l,b)*findgcd(l,b)); 26 | cout< 2 | #define pb push_back 3 | using namespace std; 4 | int main() { 5 | int tc,n,ptr=0; 6 | cin>>tc; 7 | string s; 8 | for(int i=0;i>n; 11 | vector hash; 12 | for(int j=0;j>s; 15 | bool stat=false; 16 | int a=0; 17 | while(a 0) 16 | { 17 | if (t< last) 18 | { 19 | passCount++; 20 | } 21 | } 22 | last = t; 23 | } 24 | Console.WriteLine(passCount); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kattis-Solutions/Keywords.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Keywords 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Dictionary d = new Dictionary(); 11 | int n = int.Parse(Console.ReadLine()); 12 | string stemp; 13 | for (int i = 0; i < n; i++) { 14 | stemp = Console.ReadLine().ToLower(); 15 | stemp = stemp.Replace('-', ' '); 16 | if (!d.ContainsKey(stemp)) 17 | { 18 | d.Add(stemp, 1); 19 | } 20 | } 21 | Console.WriteLine(d.Count); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/Rectangle Area.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Rectangle_Area 4 | { 5 | class Program 6 | { 7 | static float abs(float xa, float xb) 8 | { 9 | if (xa > xb) { return xa - xb; } 10 | return xb - xa; 11 | } 12 | static void Main(string[] args) 13 | { 14 | string[] sarr = Console.ReadLine().Split(' '); 15 | float area, ax, ay, bx, by; 16 | ax = float.Parse(sarr[0]); 17 | ay = float.Parse(sarr[1]); 18 | bx = float.Parse(sarr[2]); 19 | by = float.Parse(sarr[3]); 20 | area = abs(by,ay) * abs(bx,ax); 21 | Console.WriteLine("{0:F3}", area); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/Tri.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a,b,c; 6 | cin>>a>>b>>c; 7 | if(a+b==c) 8 | {cout< 2 | using namespace std; 3 | 4 | vector array_left_rotation(vector a, int n, int k) { 5 | if (k%n==0){ 6 | return a; 7 | }else{ 8 | k=k%n; 9 | for(int i=0;i> n >> k; 21 | vector a(n); 22 | for(int a_i = 0;a_i < n;a_i++){ 23 | cin >> a[a_i]; 24 | } 25 | vector output = array_left_rotation(a, n, k); 26 | for(int i = 0; i < n;i++) 27 | cout << output[i] << " "; 28 | cout << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Kattis-Solutions/Minesweeper.py: -------------------------------------------------------------------------------- 1 | def getKey(tr, tc): 2 | return str(tr)+":"+str(tc) 3 | 4 | if __name__ == "__main__": 5 | sarr = input().split(' ') 6 | nr = int(sarr[0]) 7 | nc = int(sarr[1]) 8 | nb = int(sarr[2]) 9 | 10 | tr = 0 11 | tc = 0 12 | d = dict() 13 | temps = "" 14 | 15 | for x in range(nb): 16 | sarr = input().split(' ') 17 | tr =int(sarr[0]) - 1 18 | tc = int(sarr[1]) - 1 19 | d[getKey(tr,tc)]=1 20 | 21 | for x in range(nr): 22 | # x is row 23 | temps = "" 24 | for y in range(nc): 25 | if getKey(x,y) in d : 26 | temps += "*" 27 | else: 28 | temps += "." 29 | print(temps) 30 | -------------------------------------------------------------------------------- /Kattis-Solutions/Hissing Microphone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | typedef pair pii; 6 | #define psb push_back 7 | #define mkp make_pair 8 | #define all(x) (x).begin(),(x).end() 9 | #define PI acos(-1) 10 | #define MOD 1000000007 11 | #define fff first 12 | #define sss second 13 | 14 | int main() { 15 | // your code goes here 16 | string s; 17 | cin>>s; 18 | bool hiss=false; 19 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | //Sieve of Eratosthenes 5 | //Created by Yuwono Bangun Nagoro a.k.a SurgicalSteel 6 | int main() 7 | { 8 | int num,first=0; 9 | scanf("%d",&num); 10 | vector v; 11 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | int xp,nb; 6 | cin>>xp>>nb; 7 | if(xp>nb&&xp>0&&nb>0) 8 | { 9 | if(nb*2<=xp){cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int da,ma,ya,de,me,ye; 11 | cin>>da>>ma>>ya>>de>>me>>ye; 12 | if(yaye){cout<<"10000\n";} 16 | else 17 | { 18 | if(ma>me) 19 | { 20 | cout<<(ma-me)*500<<"\n"; 21 | } 22 | else 23 | { 24 | if(da>de) 25 | { 26 | cout<<(da-de)*15; 27 | } 28 | } 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Kattis-Solutions/Candy Store.py: -------------------------------------------------------------------------------- 1 | def getInitial(name): 2 | arr = str.split(name, " ") 3 | return f"{arr[0][0]}{arr[1][0]}" 4 | 5 | if __name__ == "__main__": 6 | sarr = input().split(" ") 7 | fnc = int(sarr[0]) 8 | anc = int(sarr[1]) 9 | 10 | dname = dict() 11 | initial = "" 12 | name = "" 13 | 14 | for x in range(fnc): 15 | name = input() 16 | initial = getInitial(name) 17 | if initial in dname : 18 | dname[initial] = "ambiguous" 19 | else: 20 | dname[initial] = name 21 | 22 | for x in range(anc): 23 | initial = input() 24 | if initial in dname : 25 | print(dname[initial]) 26 | else : 27 | print("nobody") 28 | 29 | -------------------------------------------------------------------------------- /Kattis-Solutions/Cokolada.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int szw,whl=1,build=0,step=0,tempwhl; 5 | scanf("%d",&szw); 6 | while(whl1) 12 | { 13 | build+=(whl/2); 14 | whl=whl/2; 15 | step++; 16 | } 17 | else if(step==0&&whl==1) 18 | { 19 | build++; 20 | whl=0; 21 | step++; 22 | } 23 | else 24 | { 25 | if(build+(whl/2)<=szw) 26 | { 27 | build+=(whl/2); 28 | if(whl>1){whl=whl/2;} 29 | step++; 30 | } 31 | else 32 | { 33 | whl=whl/2; 34 | step++; 35 | } 36 | } 37 | } 38 | printf("%d %d\n",tempwhl,step); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Hackerrank/Sequence Equation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define MOD 1000000007 9 | vector v; 10 | int getindex(int x){ 11 | vector::iterator it=find(all(v),x); 12 | if (it != v.end()){ 13 | return distance(v.begin(),it)+1; 14 | } 15 | return -1; 16 | } 17 | 18 | int main() { 19 | // your code goes here 20 | int n,t; 21 | scanf("%d",&n); 22 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | string s; 6 | cin>>s; 7 | int p=s.length(); 8 | int row=1,col=p,i=1; 9 | while(row<=col&&i<=p) 10 | { 11 | if(p%i==0&&i>row&&(p/i)>=i){row=i;col=p/i;} 12 | i++; 13 | } 14 | int ctr=0; 15 | string mat[row][col]; 16 | for(int i=0;i 2 | #define pb push_back 3 | using namespace std; 4 | struct point{int x,y;}; 5 | bool ceksinggung(point a, point b) 6 | { 7 | if(a.x==b.x||a.y==b.y||(a.x+a.y)==(b.x+b.y)||(a.x-a.y)==(b.x-b.y)||(a.y-a.x)==(b.y-b.x)) 8 | {return true;} 9 | else{return false;} 10 | } 11 | int main() { 12 | point temp; 13 | int sz; 14 | cin>>sz; 15 | vector v; 16 | for(int i=0;i>temp.x>>temp.y; 19 | v.pb(temp); 20 | } 21 | bool truth=true; 22 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>ba>>br>>bs>>aa>>as; 27 | while(ats<=((br-ba)*bs)){ 28 | ats+=as; 29 | y++; 30 | } 31 | cout<ma&&mb>mc) || (mb Math.Abs(mb - ma)) { Console.WriteLine("accelerated"); } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Hackerrank/Find Point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | struct point{int x,y;}; 8 | int absolutey(int x) 9 | {if(x<0){return x*-1;}else{return x;}} 10 | point solve(int ax,int ay,int bx, int by) 11 | { 12 | point p; 13 | p.x=ax+(2*(bx-ax)); 14 | p.y=ay+(2*(by-ay)); 15 | return p; 16 | } 17 | int main() { 18 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 19 | int tc,ax,ay,bx,by,temp=0; 20 | cin>>tc; 21 | point res; 22 | while(temp>ax>>ay>>bx>>by; 25 | res=solve(ax,ay,bx,by); 26 | cout<= rsq) 18 | { 19 | Console.WriteLine("{0} {1}", x, y); 20 | breaker = true; 21 | break; 22 | } 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Hackerrank/String Construction.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'stringConstruction' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | def stringConstruction(s): 17 | d = dict() 18 | for x in range (len(s)): 19 | if s[x] not in d: 20 | d[s[x]] = 1 21 | return len(d) 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | q = int(input().strip()) 28 | 29 | for q_itr in range(q): 30 | s = input() 31 | 32 | result = stringConstruction(s) 33 | 34 | fptr.write(str(result) + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Kattis-Solutions/Ragged Right.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Ragged_Right 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | List l = new List(); 12 | string s = Console.ReadLine(); 13 | while (!string.IsNullOrEmpty(s)) 14 | { 15 | l.Add(s); 16 | s = Console.ReadLine(); 17 | } 18 | int longest = l.Max(x => x.Length); 19 | long count = 0; 20 | for (int i = 0; i < l.Count - 1; i++) { 21 | count += (long)((longest - l[i].Length) * (longest - l[i].Length)); 22 | } 23 | Console.WriteLine(count); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kattis-Solutions/Reseto.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | vector num; 5 | int main() { 6 | int n,k,iter=0,currprime,finalidx; 7 | scanf("%d %d",&n,&k); 8 | for(int i=1;i0&&num[i]%currprime==0) 26 | { 27 | iter++; 28 | if(iter==k){finalidx=num[i];break;} 29 | num[i]=-1; 30 | } 31 | else{i+=currprime;} 32 | } 33 | } 34 | printf("%d\n",finalidx); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Kattis-Solutions/Vedur Lokadar Heidar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Vedur_Lokadar_Heidar 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int currentWind = int.Parse(Console.ReadLine()); 10 | int nc = int.Parse(Console.ReadLine()); 11 | string[] sarr; 12 | for(int i = 0; i < nc; i++) 13 | { 14 | sarr = Console.ReadLine().Split(' '); 15 | if (int.Parse(sarr[1]) < currentWind) 16 | { 17 | Console.WriteLine(sarr[0] + " " + "lokud"); 18 | } 19 | else 20 | { 21 | Console.WriteLine(sarr[0] + " " + "opin"); 22 | } 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Hackerrank/Lonely Integer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,res=0; 8 | cin>>n; 9 | int arrnum[n]; 10 | for(int i=0;i>arrnum[i];} 11 | if(n>2) 12 | { 13 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | long long sumevenfib(long long n) 8 | { 9 | long long counter=0,curr=1,i=0,j=1; 10 | while (curr<=n) 11 | { 12 | if(curr%2==0){counter+=curr;} 13 | i=j; 14 | j=curr; 15 | curr=i+j; 16 | } 17 | return counter; 18 | } 19 | 20 | int main() { 21 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 22 | int tc; 23 | cin>>tc; 24 | long long temp,res[tc]; 25 | for(int i=0;i>temp; 28 | res[i]=sumevenfib(temp); 29 | } 30 | for(int i=0;i raw = new List(); 12 | int tot = 0; 13 | int n = int.Parse(Console.ReadLine()); 14 | string[] sarr = Console.ReadLine().Split(); 15 | for(int x = 0; x < n; x++) { raw.Add(int.Parse(sarr[x])); } 16 | raw = raw.OrderBy(x => x).ToList(); 17 | for (int x = 0; x < n; x++) 18 | { 19 | if (x == 0) { tot += raw[x]; } 20 | else if ((raw[x] - raw[x - 1]) > 1) { tot += raw[x]; } 21 | } 22 | Console.WriteLine(tot); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Hackerrank/Picking Numbers.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | func maxi(a,b int) int{ 5 | if a>b{ 6 | return a 7 | }else{ 8 | return b 9 | } 10 | } 11 | 12 | func main() { 13 | var m map[int]int 14 | m= make(map[int]int) 15 | var sz,t,mm,rm,tm int 16 | mm=0 17 | rm=0 18 | fmt.Scanf("%d",&sz) 19 | for i:=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n,k; 9 | string s,res; 10 | cin>>n>>s>>k; 11 | char koleksi[n]; 12 | strcpy(koleksi,s.c_str()); 13 | k=k%26; 14 | for(int i=0;i=65&&koleksi[i]<=90)||(koleksi[i]>=97&&koleksi[i]<=122)) 17 | { 18 | if(koleksi[i]>=65&&koleksi[i]<=90) 19 | {if(koleksi[i]+k>90){koleksi[i]=koleksi[i]+k-26;}else{koleksi[i]+=k;}} 20 | if(koleksi[i]>=97&&koleksi[i]<=122) 21 | {if(koleksi[i]+k>122){koleksi[i]=koleksi[i]+k-26;}else{koleksi[i]+=k;}} 22 | } 23 | } 24 | stringstream ss; 25 | ss<>res; 27 | cout<= h) 19 | { 20 | count++; 21 | break; 22 | } 23 | currHeight -= m; 24 | count++; 25 | } 26 | 27 | Console.WriteLine("{0}", count); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Hackerrank/Beautiful Binary String.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | class Solution { 6 | 7 | static void Main(String[] args) { 8 | int n = Convert.ToInt32(Console.ReadLine()); 9 | string s = Console.ReadLine(); 10 | if(n<3){Console.WriteLine("0");} 11 | else if(n==3) 12 | { 13 | if(s.Equals("010")){Console.WriteLine("1");} 14 | else{Console.WriteLine("0");} 15 | } 16 | else 17 | { 18 | int counter=0; 19 | int i=0; 20 | while(i 2 | #include 3 | #define psb push_back 4 | using namespace std; 5 | int main() { 6 | int tc,sz,tmp; 7 | scanf("%d",&tc); 8 | int num[1000001]={0}; 9 | long long int tot,r; 10 | for(int i=0;i1) 23 | { 24 | r=num[x]; 25 | tot+=(r*(r-1)); 26 | }/*((ctr[x]*(ctr[x]-1))/2)*/ 27 | num[x]=0; 28 | } 29 | printf("%lld\n",tot); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Kattis-Solutions/Powers of Two Easy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Powers_of_2_Easy 4 | { 5 | class Program 6 | { 7 | static string getpoweroftwo(int n) 8 | { 9 | return ((int) Math.Pow(2, n)).ToString(); 10 | } 11 | 12 | static void Main(string[] args) 13 | { 14 | int n, e; 15 | string[] sarr = Console.ReadLine().Split(' '); 16 | n = int.Parse(sarr[0]); 17 | e = int.Parse(sarr[1]); 18 | string pot = getpoweroftwo(e); 19 | string bs = ""; 20 | int nc = 0; 21 | for(int i = 0; i <= n; i++) 22 | { 23 | bs= i.ToString(); 24 | if (bs.Contains(pot)) { nc++; } 25 | } 26 | Console.WriteLine(nc); 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Kattis-Solutions/Das Blinkenlights.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Das_Blinkenlights 3 | { 4 | class Program 5 | { 6 | static int gcd(int a, int b) 7 | { 8 | return b == 0 ? a : gcd(b, a % b); 9 | } 10 | static int lcm(int a, int b) 11 | { 12 | return a* b / gcd(a, b); 13 | } 14 | static void Main(string[] args) 15 | { 16 | int p, q, s; 17 | string[] sarr = Console.ReadLine().Split(' '); 18 | p = int.Parse(sarr[0]); 19 | q = int.Parse(sarr[1]); 20 | s = int.Parse(sarr[2]); 21 | 22 | bool same = false; 23 | int lcmv = lcm(p, q); 24 | same = lcmv >= 1 && lcmv <= s; 25 | Console.WriteLine(same ? "yes" : "no"); 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Kattis-Solutions/Digit Product.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Digit_Product 4 | { 5 | class Program 6 | { 7 | static int getProductDigit(int x) 8 | { 9 | if (x <= 0) { return 0; } 10 | int prod = 1, tmpmod = 0; 11 | while (x > 0) 12 | { 13 | tmpmod = x % 10; 14 | if (tmpmod > 0) { prod *= tmpmod; } 15 | x -= tmpmod; 16 | x /= 10; 17 | } 18 | return prod; 19 | } 20 | static void Main(string[] args) 21 | { 22 | int x = int.Parse(Console.ReadLine()); 23 | while (x >= 10) { 24 | x = getProductDigit(x); 25 | if (x < 10) { break; } 26 | } 27 | Console.WriteLine(x); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Kattis-Solutions/Almost Perfect.cpp: -------------------------------------------------------------------------------- 1 | //template provided by SurgicalSteel a.k.a Yuwono Bangun Nagoro 2 | #include 3 | #define psb push_back 4 | using namespace std; 5 | long long int absolutey(long long int x) 6 | { 7 | if(x>0){return x;} 8 | else{return x*-1;} 9 | } 10 | int main() 11 | { 12 | int x; 13 | long long int res=0,a=0; 14 | while(cin>>x) 15 | { 16 | vector v; 17 | for(int i=1;i<=sqrt(x);++i) 18 | { 19 | if(i==1){v.psb(i);} 20 | else if(x%i==0&&(x/i)!=i){v.psb(i);v.psb(x/i);} 21 | else if(x%i==0&&(x/i)==i){v.psb(i);} 22 | } 23 | res=0; 24 | a=0; 25 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | #define psb push_back 5 | int main() { 6 | int tc,sz,t,ct,x; 7 | lli tot; 8 | bool ends; 9 | scanf("%d",&tc); 10 | for(int i=0;itarr[x]&&x>=0){ 22 | tot+=(tarr[ct]-tarr[x]); 23 | } 24 | else if(tarr[ct]<=tarr[x]&&x>=0){ 25 | ct=x; 26 | } 27 | x--; 28 | if(x<0){ends=true;} 29 | } 30 | printf("%lld\n",tot); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Kattis-Solutions/Falling Apart.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | typedef pair pii; 6 | #define psb push_back 7 | #define mkp make_pair 8 | #define all(x) (x).begin(),(x).end() 9 | #define PI acos(-1) 10 | #define MOD 1000000007 11 | #define fff first 12 | #define sss second 13 | bool cmp(int i, int j){ 14 | return i>j; 15 | } 16 | int main() { 17 | // your code goes here 18 | int n,t,ca=0,cb=0; 19 | vector v; 20 | cin>>n; 21 | for(int i=0;i>t; 23 | v.psb(t); 24 | } 25 | sort(all(v),cmp); 26 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | 11 | int main() { 12 | // your code goes here 13 | int num[9],temp,tsum=0,xa,xb; 14 | for(int i=0;i<9;i++){ 15 | scanf("%d",&num[i]); 16 | tsum+=num[i]; 17 | } 18 | for(int i=0;i<9;i++){ 19 | for(int j=0;j<9;j++){ 20 | if(i!=j&&(tsum-num[i]-num[j]==100)){ 21 | xa=i; 22 | xb=j; 23 | } 24 | } 25 | } 26 | for(int x=0;x<9;x++){ 27 | if(x!=xa&&x!=xb){ 28 | printf("%d\n",num[x]); 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Hackerrank/Game of Thrones 1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | class Solution { 6 | static void Main(String[] args) { 7 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ 8 | string s=Console.ReadLine(); 9 | byte[] dec = Encoding.ASCII.GetBytes(s); 10 | int[] hash=new int[26]; 11 | for(int i=0;i<26;i++){hash[i]=0;} 12 | for(int i=0;i1){valid=false;} 20 | x++; 21 | } 22 | if(valid){Console.WriteLine("YES");}else{Console.WriteLine("NO");} 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis-Solutions/Provinces and Gold.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Provinces_and_Gold 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] cards = Console.ReadLine().Split(" "); 10 | int gold = int.Parse(cards[0]); 11 | int silver = int.Parse(cards[1]); 12 | int copper = int.Parse(cards[2]); 13 | 14 | int tot = (gold * 3) + (silver * 2) + (copper * 1); 15 | string a = "", b = ""; 16 | if (tot >= 8) { a = "Province"; } else if(tot>=5){ a = "Duchy"; } else if (tot >= 2) { a = "Estate"; } 17 | if (tot >= 6) { b = "Gold"; } else if (tot >= 3) { b = "Silver"; } else if (tot >= 0) { b = "Copper"; } 18 | if (a.Length == 0) { Console.WriteLine(b); } else { Console.WriteLine("{0} or {1}",a,b); } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kattis-Solutions/Zamka.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int toInt(string x) 4 | { 5 | istringstream ss(x); 6 | int a; 7 | ss>>a; 8 | return a; 9 | } 10 | string tostr(int x) 11 | { 12 | ostringstream ss; 13 | ss< 2 | using namespace std; 3 | string solve(string enc) 4 | { 5 | int res =(int) sqrt((double) enc.length()); 6 | int curr,counter=0; 7 | string builder=""; 8 | int pos=res-1; 9 | int awal=pos; 10 | while(counter>tc; 30 | for(int i=0;i>inp; 33 | cout< 2 | using namespace std; 3 | int toInt(string x) 4 | { 5 | istringstream ss(x); 6 | int a; 7 | ss>>a; 8 | return a; 9 | } 10 | int main() { 11 | int sz; 12 | string s; 13 | cin>>sz; 14 | int mat[sz][sz]; 15 | for(int i=0;i>s; 18 | for(int x=0;x0&&i0&&jmat[j-1][i]&&mat[j][i]>mat[j+1][i]&&mat[j][i]>mat[j][i-1]&&mat[j][i]>mat[j][i+1]) 28 | {cout<<"X";}else{cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int toint(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>ax>>ay>>bx>>by>>l; 27 | sp=(abs(ax-bx)+abs(ay-by)); 28 | if(l 2 | using namespace std; 3 | struct point{int x;int y;}; 4 | int absolutey(int x) 5 | {if(x<0){return x*=-1;}else{return x;}} 6 | float area(point a, point b, point c) 7 | { 8 | float res=abs(((a.x*(b.y-c.y))+(b.x*(c.y-a.y))+(c.x*(a.y-b.y)))/2.0); 9 | return res; 10 | } 11 | bool check(point a,point b, point c, point p) 12 | { 13 | float abc=area(a,b,c); 14 | float pab=area(p,a,b); 15 | float pbc=area(p,b,c); 16 | float pac=area(p,a,c); 17 | return (abc==pab+pbc+pac); 18 | } 19 | int main() { 20 | point a,b,c,p; 21 | cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y; 22 | int num,ctr=0; 23 | cin>>num; 24 | float tarea= area(a,b,c); 25 | printf("%.1f\n",tarea); 26 | //cout.precision(1)<>p.x>>p.y; 30 | if(check(a,b,c,p)){ctr++;} 31 | } 32 | cout< 2 | using namespace std; 3 | string solve(string s) 4 | { 5 | string builder=""; 6 | int l=s.length(); 7 | int x=(int)ceil(sqrt((double) l)); 8 | string mat[x][x]; 9 | int pos=0; 10 | for(int j=0;j=0;j--) 22 | { 23 | if(mat[i][j]!="*"){builder+=mat[i][j];} 24 | } 25 | } 26 | return builder; 27 | } 28 | int main() { 29 | int tc; 30 | cin>>tc; 31 | string s; 32 | for(int i=0;i>s; 35 | cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int toint(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>q>>m; 31 | for(int i=0;i>t; 33 | if(i==0){ 34 | tot = q-t; 35 | }else{ 36 | tot +=q; 37 | tot -=t; 38 | } 39 | } 40 | cout< 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int tc,temp; 8 | cin>>tc; 9 | vector vh,vd; 10 | for(int i=0;i<6;i++) 11 | {vh.pb(0);} 12 | for(int i=0;i>temp; 15 | vd.pb(temp); 16 | vh[temp-1]++; 17 | } 18 | int i=5; 19 | bool found=false; 20 | while(i>=0&&!found) 21 | { 22 | if(vh[i]==1) 23 | { 24 | vector::iterator iter=vd.begin(); 25 | iter=find(vd.begin(),vd.end(),i+1); 26 | if(iter!=vd.end()) 27 | { 28 | cout< 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | string low(string inp) 6 | { 7 | string res; 8 | locale loc; 9 | for(string::size_type i=0;i v; 17 | vector::iterator iter=v.begin(); 18 | while(cin>>s) 19 | { 20 | if(i==0){v.pb(low(s));cout< 2 | using namespace std; 3 | #define psb push_back 4 | int main() { 5 | int nchap,maxprob,temp; 6 | scanf("%d %d",&nchap,&maxprob); 7 | int npage=1,counter,last,nres=0; 8 | for(int i=0;i vi; 12 | for(int a=0;a 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>n; 27 | while(n--){ 28 | cin>>t; 29 | b[t-1]++; 30 | } 31 | 32 | for(int i=4;i>=0;i--){ 33 | if(max(m,b[i])==b[i]){ 34 | d=i; 35 | m=b[i]; 36 | } 37 | } 38 | cout< list = new List(); 11 | for(int i = 0; i < line.Length; i++) 12 | { 13 | if(i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int toint(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | 11 | int main() { 12 | // your code goes here 13 | int sw,so; 14 | bool breaker=false; 15 | while(!breaker){ 16 | cin>>sw>>so; 17 | if(sw==0 && so == 0){ 18 | breaker = true; 19 | }else{ 20 | if(sw+so==13){ 21 | cout<<"Never speak again.\n"; 22 | }else if(sw>so){ 23 | cout<<"To the convention.\n"; 24 | }else if(sw 2 | using namespace std; 3 | #define pb push_back 4 | #define fs first 5 | #define sc second 6 | #define mp make_pair 7 | int solve(vector> spdh) 8 | { 9 | if(spdh.size()==1){return spdh[0].fs*spdh[0].sc;} 10 | else 11 | { 12 | int tot=0; 13 | for(int i=0;i>n; 24 | while(n!=-1) 25 | { 26 | vector> spdh; 27 | for(int i=0;i>spd>>h; 30 | spdh.pb(mp(spd,h)); 31 | } 32 | cout<>n; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Kattis-Solutions/Semafori.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type light struct { 6 | pos, red, green int 7 | } 8 | 9 | func absolutey(x int) int { 10 | if x < 0 { 11 | return x * -1 12 | } else { 13 | return x 14 | } 15 | } 16 | func main() { 17 | var nl, l, tm, progdist, currl int 18 | fmt.Scanf("%d %d", &nl, &l) 19 | col := make([]light, nl) 20 | for i := 0; i < nl; i++ { 21 | fmt.Scanf("%d %d %d", &col[i].pos, &col[i].red, &col[i].green) 22 | } 23 | progdist = 0 24 | currl = 0 25 | tm = 0 26 | for progdist < l { 27 | if currl < nl && progdist == col[currl].pos { 28 | if (tm % (col[currl].red + col[currl].green)) < col[currl].red { 29 | tm += absolutey(col[currl].red - (tm % (col[currl].red + col[currl].green))) 30 | } else { 31 | tm++ 32 | progdist++ 33 | } 34 | currl++ 35 | } else { 36 | tm++ 37 | progdist++ 38 | } 39 | } 40 | fmt.Printf("%d\n", tm) 41 | } 42 | -------------------------------------------------------------------------------- /Kattis-Solutions/Honour Thy Apaxian Parent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Honour_Thy_Apaxian_Parent 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] arr = Console.ReadLine().Split(" "); 10 | string res = ""; 11 | if (arr[0].EndsWith("e")) 12 | { 13 | res = arr[0] + "x" + arr[1]; 14 | }else if (arr[0].EndsWith("a") || arr[0].EndsWith("i") || arr[0].EndsWith("o") || arr[0].EndsWith("u")) 15 | { 16 | res = arr[0].Substring(0, arr[0].Length - 1) + "ex" + arr[1]; 17 | }else if (arr[0].EndsWith("ex")) 18 | { 19 | res = arr[0] + arr[1]; 20 | } 21 | else 22 | { 23 | res = arr[0] + "ex" + arr[1]; 24 | } 25 | Console.WriteLine(res); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Hackerrank/Maximizing XOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | /* 20 | * Complete the function below. 21 | */ 22 | int maxXor(int l, int r) { 23 | int maxi=-100; 24 | for(int i=l;i<=r;i++) 25 | { 26 | for(int j=l;j<=r;j++) 27 | { 28 | if((i^j)>maxi){maxi=i^j;} 29 | } 30 | } 31 | return maxi; 32 | } 33 | 34 | int main() { 35 | int res; 36 | int _l; 37 | cin >> _l; 38 | 39 | int _r; 40 | cin >> _r; 41 | 42 | res = maxXor(_l, _r); 43 | cout << res; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Kattis-Solutions/Bijele.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //created by Yuwono Bangun Nagoro a.k.a SurgicalSteel 3 | #define psb push_back 4 | #define Mas_Bangun using 5 | #define cinta namespace 6 | #define Mbak_GitaGutawa std 7 | Mas_Bangun cinta Mbak_GitaGutawa; 8 | int main() { 9 | int ki,qu,ro,bi,kn,pa; 10 | cin>>ki>>qu>>ro>>bi>>kn>>pa; 11 | if(ki==0){ki=1;} 12 | else if (ki==1){ki=0;} 13 | else {ki=1-ki;} 14 | if(qu==0){qu=1;} 15 | else if (qu==1){qu=0;} 16 | else {qu=1-qu;} 17 | if(ro<2){ro=2-ro;} 18 | else if (ro==2){ro=0;} 19 | else {ro=2-ro;} 20 | if(bi<2){bi=2-bi;} 21 | else if (bi==2){bi=0;} 22 | else {bi=2-bi;} 23 | if(kn<2){kn=2-kn;} 24 | else if (kn==2){kn=0;} 25 | else {kn=2-kn;} 26 | if(pa<8){pa=8-pa;} 27 | else if (pa==8){pa=0;} 28 | else {pa=8-pa;} 29 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | #define pb push_back 9 | int getdiff(int a, int b) 10 | { 11 | int diff; 12 | (a-b)<0?diff=(a-b)*-1:diff=(a-b); 13 | return diff; 14 | } 15 | int main() { 16 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 17 | int n,x; 18 | cin>>n; 19 | vector col; 20 | for(int i=0;i>x; 23 | col.pb(x); 24 | } 25 | sort(col.begin(),col.end()); 26 | int mindiff=2000000000; 27 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define pb push_back 7 | #define mp make_pair 8 | using namespace std; 9 | bool isprime(int a) { 10 | if(a==1){return false;} 11 | for (int i=2;i*i<=a;i++) 12 | if(a%i==0) 13 | return false; 14 | return true; 15 | } 16 | struct pas{int first;int second;}; 17 | int main() { 18 | int tc,tmp; 19 | pas ptemp; 20 | cin>>tc; 21 | for(int i=0;i>tmp; 24 | vector vp; 25 | for(int x=2;x<=tmp;x++) 26 | { 27 | if(isprime(x)&&isprime(tmp-x)&&x<=(tmp-x)) 28 | { 29 | ptemp.first=x; 30 | ptemp.second=tmp-x; 31 | vp.pb(ptemp); 32 | } 33 | } 34 | cout< 2 | using namespace std; 3 | string tostr(int x) 4 | { 5 | ostringstream ss; 6 | ss<>iy; 17 | if (iy<1918){ 18 | l=(iy%4==0); 19 | }else{ 20 | l=((iy%400==0) || (iy%4==0 && iy%100!=0)); 21 | } 22 | v=(256*12)/cm; 23 | for(int i=0;i0){m++;} 31 | sd=tostr(d); 32 | sm=tostr(m); 33 | if (sd.length()==1){sd="0"+sd;} 34 | if (sm.length()==1){sm="0"+sm;} 35 | cout< b && a % 2 == 0) { a = a / 2; res++; } else 20 | if (a > b && a % 2 == 1) { a = (a +1)/ 2; res += 2; } 21 | else if (a < b) { res += (b - a); a = b; } 22 | 23 | if (a == b) { breaker = true; } 24 | } 25 | } 26 | Console.WriteLine(res); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Kattis-Solutions/Odd Man Out.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int tc,sz,temp; 8 | cin>>tc; 9 | for(int i=0;i>sz; 12 | vector v; 13 | for(int j=0;j>temp; 16 | v.pb(temp); 17 | } 18 | sort(v.begin(),v.end()); 19 | bool found=false; 20 | int j=0; 21 | while(j<=sz-1&&!found) 22 | { 23 | if(j==0&&v[j]!=v[j+1]) 24 | {cout<<"Case #"<0&&j 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | struct cell{ 11 | int x,y; 12 | }; 13 | double dist(cell a, cell b){ 14 | double xt = double(abs(a.x-b.x)*abs(a.x-b.x)); 15 | double yt = double(abs(a.y-b.y)*abs(a.y-b.y)); 16 | return sqrt(xt+yt); 17 | } 18 | int main() { 19 | cell arr[9]; 20 | int t; 21 | double tot=0; 22 | for(int j=0;j<3;j++){ 23 | for(int i=0;i<3;i++){ 24 | cin>>t; 25 | cell ct; 26 | ct.x=i; 27 | ct.y=j; 28 | arr[t-1]=ct; 29 | } 30 | } 31 | for(int i=0;i<8;i++){ 32 | tot+=dist(arr[i],arr[i+1]); 33 | } 34 | printf("%.10f\n",tot); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Hackerrank/Project-Euler/10-Summation of Primes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define psb push_back 3 | using namespace std; 4 | vector vp; 5 | void precompute() 6 | { 7 | int num=1000000,first=0; 8 | vector v; 9 | for(int i=0;i name=new List(); 12 | int n; 13 | inp=Console.ReadLine(); 14 | int.TryParse(inp, out n); 15 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>tc; 27 | while(tc--){ 28 | cin>>pa>>pb>>pc; 29 | if(abs(pa-pc)==abs(pb-pc)){ 30 | cout<<"Mouse C\n"; 31 | }else if (abs(pa-pc)abs(pb-pc)){ 34 | cout<<"Cat B\n"; 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Hackerrank/Minimum Absolute Difference in an Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss< v; 26 | int n,t; 27 | int mini=1000000000; 28 | scanf("%d",&n); 29 | for(int i=0;i 2 | using namespace std; 3 | #define PI 3.1415926535897932384626433832795 4 | 5 | 6 | int main() { 7 | int tc,num; 8 | float ang,currang=0; 9 | float sca; 10 | cin>>tc; 11 | for(int i=0;i>num; 14 | float posx=0.00000000,posy=0.000000000; 15 | for(int j=0;j>ang>>sca; 18 | if(j==0) 19 | { 20 | currang=90+ang; 21 | if(currang<0){currang+=360;} 22 | } 23 | else 24 | { 25 | currang+=ang; 26 | if(currang<0){currang+=360;} 27 | } 28 | posx+=(sca*(cos((double) ((currang)*PI/180)))); 29 | posy+=(sca*(sin((double) ((currang)*PI/180)))); 30 | } 31 | printf("%.6f %.6f \n",posx,posy);//cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int months[95796]; 11 | 12 | void precalc(){ 13 | memset(months,0,sizeof(months)); 14 | int curr=3; 15 | for(int i=curr;i<95796;i+=26){ 16 | months[i]++; 17 | } 18 | } 19 | bool getposs(int idx){ 20 | for(int i=idx;i0){ 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | int getidx(int y){ 28 | return (y-2018)*12; 29 | } 30 | int main() { 31 | // your code goes here 32 | precalc(); 33 | int y; 34 | cin>>y; 35 | if(getposs(getidx(y))){ 36 | cout<<"yes\n"; 37 | }else{ 38 | cout<<"no\n"; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Kattis-Solutions/Moscow Dream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Moscow_Dream 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] abcn = Console.ReadLine().Split(" "); 10 | int a = int.Parse(abcn[0]); 11 | int b = int.Parse(abcn[1]); 12 | int c = int.Parse(abcn[2]); 13 | int n = int.Parse(abcn[3]); 14 | 15 | if(a == 0 || b == 0 || c == 0) 16 | { 17 | Console.WriteLine("NO"); 18 | return; 19 | } 20 | 21 | if(n<3){ 22 | Console.WriteLine("NO"); 23 | return; 24 | } 25 | 26 | if((a+b+c) >= n) 27 | { 28 | Console.WriteLine("YES"); 29 | } 30 | else 31 | { 32 | Console.WriteLine("NO"); 33 | } 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Kattis-Solutions/Planting Trees.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int toint(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<b; 28 | } 29 | int main() { 30 | // your code goes here 31 | int n,t,maxi=0; 32 | vector v; 33 | cin>>n; 34 | for(int i=0;i>t; 36 | v.psb(t); 37 | } 38 | sort(all(v),compare); 39 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<y;} 24 | int main() { 25 | // your code goes here 26 | int tc,tmp,tot=0; 27 | scanf("%d",&tc); 28 | vector v; 29 | for(int i=0;i d = new Dictionary(); 14 | string s = Console.ReadLine(); 15 | while (!string.IsNullOrEmpty(s)) 16 | { 17 | string[] sp = s.Split(); 18 | d.Add(sp[1],sp[0]); 19 | s = Console.ReadLine(); 20 | } 21 | s = Console.ReadLine(); 22 | while (!string.IsNullOrEmpty(s)) 23 | { 24 | if (d.ContainsKey(s)) { Console.WriteLine(d[s]); } 25 | else 26 | {Console.WriteLine("eh");} 27 | s = Console.ReadLine(); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Kattis-Solutions/Bus Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | 6 | int main() { 7 | int tc,x; 8 | vector stat; 9 | cin>>tc; 10 | for(int i=0;i>x; 13 | stat.pb(x); 14 | } 15 | sort(stat.begin(),stat.end()); 16 | int i=0; 17 | while(i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | 11 | int main() { 12 | // your code goes here 13 | int idx,nt,temp,nb,sc,possb,pvhm; 14 | vector pt,pb,ptb; 15 | cin>>nt; 16 | 17 | for(int i=0;i>temp; 19 | pt.psb(temp); 20 | } 21 | cin>>nb; 22 | for(int i=0;i>temp; 24 | pb.psb(temp); 25 | } 26 | for(int i=0;i>possb; 28 | for(int j=0;j>temp; 30 | ptb.psb(pb[temp-1]+pt[i]); 31 | } 32 | } 33 | cin>>pvhm; 34 | sort(all(ptb)); 35 | sc=(pvhm - (pvhm%ptb[0]))/ptb[0]; 36 | cout<0) 16 | { 17 | Dictionary d = new Dictionary(); 18 | for(int i=0;i lm = new List(); 13 | for(int i = 0; i < n; i++) 14 | { 15 | sarr = Console.ReadLine().Split(' '); 16 | if (i == 0) 17 | { 18 | for(int x = 0; x < sarr.Length; x++) 19 | { 20 | if (x == 0) { nr = int.Parse(sarr[x]); } else { lm.Add(sarr[x]); } 21 | } 22 | } 23 | } 24 | //lm.Sort(); 25 | Console.WriteLine(nr); 26 | for(int i = lm.Count - 1; i >= 0; i--) { Console.WriteLine(lm[i]); } 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Kattis-Solutions/Pot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Pot 8 | { 9 | class Program 10 | { 11 | static int pangkat(int nb, int np) 12 | { 13 | if (np == 0) { return 1; } 14 | else { return nb * pangkat(nb, np - 1); } 15 | } 16 | static void Main(string[] args) 17 | { 18 | int tc = int.Parse(Console.ReadLine()); 19 | int total = 0; 20 | for (int x = 0; x < tc; ++x) 21 | { 22 | string temp = Console.ReadLine(); 23 | int nbase = int.Parse(temp.Substring(0, temp.Length - 1)); 24 | int npow = int.Parse(temp.Substring(temp.Length - 1, 1)); 25 | total += pangkat(nbase, npow); 26 | } 27 | Console.WriteLine(total); 28 | Console.ReadLine(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Hackerrank/Manasa and Stones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define psb push_back 4 | using namespace std; 5 | void solve(int n, int a, int b) 6 | { 7 | vector res; 8 | int maxi=max(a,b); 9 | int mini=min(a,b); 10 | int mat[n][n-1]; 11 | int sel; 12 | for(int j=0;j0&&i::iterator iter=unique(res.begin(),res.end()); 23 | res.resize(distance(res.begin(),iter)); 24 | for(int i=0;i 2 | #include 3 | #define pb push_back 4 | using namespace std; 5 | string solve(vector col) 6 | { 7 | bool truth=true; 8 | for(int i=0;i>tc; 36 | for(int i=0;i>size; 40 | vector col; 41 | for(int j=0;j>temp;col.pb(temp);} 43 | cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss< 0) { nc++; } 29 | } 30 | Console.WriteLine(nc); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Kattis-Solutions/Paradox With Averages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int tc,ncs,nec; 6 | float temp,totcs,totec; 7 | scanf("%d",&tc); 8 | while(tc--){ 9 | totcs=0; 10 | totec=0; 11 | scanf("%d %d",&ncs,&nec); 12 | float avcs, avec; 13 | vector vcs,vec; 14 | for(int i=0;iavcs&&avresec>avec){counter++;} 32 | x++; 33 | } 34 | printf("%d\n",counter); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Hackerrank/Make it Anagram.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | class Solution { 6 | static int absolutey(int a) 7 | {if(a<0){return a*-1;}else{return a;}} 8 | static void Main(String[] args) { 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ 10 | string a=Console.ReadLine(); 11 | string b=Console.ReadLine(); 12 | int[] hasha,hashb; 13 | int counter=0; 14 | hasha=new int [26]; 15 | hashb=new int [26]; 16 | for(int i=0;i<26;i++){hasha[i]=0;hashb[i]=0;} 17 | byte[] deca = Encoding.ASCII.GetBytes(a); 18 | byte[] decb = Encoding.ASCII.GetBytes(b); 19 | for(int i=0;i 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | char toCharSingle(string x) 11 | { 12 | char a[1]; 13 | strncpy(a,x.c_str(),sizeof(a)); 14 | return a[0]; 15 | } 16 | int main() { 17 | // your code goes here 18 | int len; 19 | string sa,sb; 20 | int hasha[26],hashb[26]; 21 | memset(hasha,0,sizeof(hasha)); 22 | memset(hashb,0,sizeof(hashb)); 23 | cin>>len>>sa>>sb; 24 | int rres=0,sres=0; 25 | for(int i=0;i0{ 30 | om[as[i]]-- 31 | }else{ 32 | valid =false 33 | break 34 | } 35 | }else{ 36 | valid=false 37 | } 38 | } 39 | if valid{ 40 | fmt.Printf("Yes\n") 41 | }else{ 42 | fmt.Printf("No\n") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Kattis-Solutions/Event Planning.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Event_Planning 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string[] sarr; 10 | sarr = Console.ReadLine().Split(' '); 11 | int np = int.Parse(sarr[0]); 12 | int bud = int.Parse(sarr[1]); 13 | int nho = int.Parse(sarr[2]); 14 | int nwe = int.Parse(sarr[3]); 15 | int cpt,mini=int.MaxValue, cpn; 16 | for(int i = 0; i < nho; i++) 17 | { 18 | cpn = int.Parse(Console.ReadLine()); 19 | sarr = Console.ReadLine().Split(' '); 20 | for(int x = 0; x < sarr.Length; x++) 21 | { 22 | if (int.Parse(sarr[x]) >= np && (np*cpn <= bud)) { mini = Math.Min(mini, np * cpn); break; } 23 | } 24 | } 25 | if (mini == int.MaxValue) { Console.WriteLine("stay home"); } else { Console.WriteLine(mini); } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Kattis-Solutions/Popular Vote.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define pb push_back 4 | #define mae max_element 5 | using namespace std; 6 | 7 | int main() { 8 | int tc; 9 | cin>>tc; 10 | for(int i=0;i>nc; 14 | vector vt,vn; 15 | for(int j=0;j>tmpv;vt.pb(tmpv);vn.pb(tmpv);} 17 | sort(vt.begin(),vt.end()); 18 | if(vt[vt.size()-1]==vt[vt.size()-2]){cout<<"no winner\n";} 19 | else 20 | { 21 | vector::iterator iter=vn.begin(); 22 | iter=find(vn.begin(),vn.end(),vt[vt.size()-1]); 23 | int sums=0; 24 | for(int j=0;j 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<b;} 29 | int main() { 30 | // your code goes here 31 | int nc,temp; 32 | vector v; 33 | cin>>nc; 34 | for(int i=0;i>temp; 36 | v.psb(temp); 37 | } 38 | lli r=0; 39 | sort(all(v),comp); 40 | for(int i=0;i 2 | #define psb push_back 3 | using namespace std; 4 | int main() { 5 | int tc,ncs,nec; 6 | float temp; 7 | long double totcs,totec; 8 | scanf("%d",&tc); 9 | while(tc--){ 10 | totcs=0; 11 | totec=0; 12 | scanf("%d %d",&ncs,&nec); 13 | long double avcs, avec; 14 | vector vcs,vec; 15 | for(int i=0;iavcs&&avresec>avec){counter++;} 33 | x++; 34 | } 35 | printf("%d\n",counter); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Codeforces-Solutions/A and B and Compilation Errors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | #define pb push_back 6 | int solve(vector big, int szbig, vector small, int szsmall) 7 | { 8 | sort(big.begin(),big.end()); 9 | sort(small.begin(),small.end()); 10 | bool sama=true; 11 | int i=0,res; 12 | while(sama&&i a,b,c; 32 | cin>>n; 33 | for(int i=0;i>x; 36 | a.pb(x); 37 | } 38 | for(int i=0;i>x; 41 | b.pb(x); 42 | } 43 | for(int i=0;i>x; 46 | c.pb(x); 47 | } 48 | cout< 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI acos(-1) 9 | #define MOD 1000000007 10 | int toint(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>n; 29 | for(int i=0;i>s; 31 | win=true; 32 | int j=0; 33 | while(j<(s.length()-1)&&win){ 34 | if(s.substr(j,1)=="C" && s.substr(j+1,1)=="D"){ 35 | win=false; 36 | }else{ 37 | j++; 38 | } 39 | 40 | } 41 | if (win){ctr++;} 42 | } 43 | cout< ls; 14 | for (int i = 0; i < tc; i++) 15 | { 16 | sarr = Console.ReadLine().Split(" "); 17 | no = int.Parse(sarr[0]); 18 | ls = new List(); 19 | for (int x = 1; x < sarr.Length; x++) { ls.Add(int.Parse(sarr[x])); } 20 | ls.Sort(); 21 | tmpCount = 0; 22 | for (int x = 0; x < ls.Count; x++) 23 | { 24 | if (x + 1 == ls.Count) { tmpCount += ls[x]; } 25 | else { tmpCount += (ls[x] - 1); } 26 | } 27 | Console.WriteLine("{0}", tmpCount); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Kattis-Solutions/Heirs Dilemma.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | namespace Heirs_Dilemma 4 | { 5 | class Program 6 | { 7 | static bool check(int n) 8 | { 9 | string ns = n.ToString(); 10 | string t; 11 | Dictionary d = new Dictionary(); 12 | for (int i = 0; i < ns.Length; i++) { 13 | t = ns.Substring(i, 1); 14 | if (d.ContainsKey(t) || t == "0") { return false; } 15 | if (n % int.Parse(t) > 0) { return false; } 16 | d.Add(t, 1); 17 | } 18 | return true; 19 | } 20 | static void Main(string[] args) 21 | { 22 | int low, high, count=0; 23 | string[] sarr = Console.ReadLine().Split(' '); 24 | low = int.Parse(sarr[0]); 25 | high = int.Parse(sarr[1]); 26 | 27 | for(int i = low; i <= high; i++) { if (check(i)) { count++; } } 28 | Console.WriteLine(count); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Hackerrank/Breaking The Records.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss<>sz; 27 | for(int i=0;i>c; 29 | if (i==0){ 30 | cmi=c; 31 | cma=c; 32 | } 33 | if (i>0){ 34 | if (ccma){ 39 | ma++; 40 | cma=c; 41 | } 42 | } 43 | } 44 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | string isfibo(long long n) 9 | { 10 | long long a=0,b=1,curr=1; 11 | string ret=" "; 12 | bool flag=true; 13 | if(n==0||n==1){return "IsFibo";} 14 | else { 15 | while (currn){ret="IsNotFibo";flag=false;} 25 | } 26 | } 27 | return ret; 28 | } 29 | int main() { 30 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 31 | int tc; 32 | cin>>tc; 33 | long long temp; 34 | string res[tc]; 35 | for(int i=0;i>temp; 38 | res[i]=isfibo(temp); 39 | } 40 | for(int i=0;i li = new List(); 13 | for(int i = 0; i < arr.Length; i++) { li.Add(int.Parse(arr[i])); } 14 | string[] grade = new string[]{ "A", "B", "C", "D", "E"}; 15 | int x = 0; 16 | bool found = false; 17 | string res = ""; 18 | 19 | while (!found && x < li.Count) 20 | { 21 | if (num >= li[x]) 22 | { 23 | found = true; 24 | res = grade[x]; 25 | } 26 | x++; 27 | } 28 | 29 | if (!found) 30 | { 31 | res = "F"; 32 | 33 | } 34 | 35 | Console.WriteLine(res); 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Hackerrank/Electronics Shop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int lli; 4 | typedef unsigned long long ull; 5 | #define psb push_back 6 | #define mkp make_pair 7 | #define all(x) (x).begin(),(x).end() 8 | #define PI 3.1415926535897932384626433832795 9 | #define MOD 1000000007 10 | int toInt(string x) 11 | { 12 | istringstream ss(x); 13 | int a; 14 | ss>>a; 15 | return a; 16 | } 17 | string tostr(int x) 18 | { 19 | ostringstream ss; 20 | ss< k,m; 27 | cin>>d>>nk>>nm; 28 | for(int i=0;i>tk; 30 | k.psb(tk); 31 | } 32 | for(int i=0;i>tm; 34 | m.psb(tm); 35 | } 36 | for(int i=0;imv&&(k[i]+m[j])<=d){ 39 | mv=(k[i]+m[j]); 40 | } 41 | } 42 | } 43 | cout<