1
+ body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}
603 Problems, 851 Solutions, 11 Languages Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 3 languages Solutions in 4 languages Solutions in 2 languages Solution in Python Solutions in 3 languages Solutions in 4 languages Solution in Python Solution in Python Solutions in 8 languages Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solutions in 8 languages Solutions in 3 languages Solution in Python Solution in Python Python
t = input ()
-
-
-def u ( pos , preference ):
- if pos == preference == "U" :
- return 0
- elif pos == preference == "D" :
- return 1
- elif pos == "U" and preference == "D" :
- return 2
- else :
- return 1
-
-
-def l ( pos , preference ):
- if pos == preference == "U" :
- return 1
- elif pos == preference == "D" :
- return 0
- elif pos == "U" and preference == "D" :
- return 1
- else :
- return 2
-
-
-def b ( pos , preference ):
- if pos == preference :
- return 0
- else :
- return 1
-
-
-pu = [ u ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "U" * ( len ( t ) - 2 ), t [ 1 :])]
-pl = [ l ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "D" * ( len ( t ) - 2 ), t [ 1 :])]
-pb = [ b ( pos , preference ) for pos , preference in zip ( t [ 0 ] + t [ 1 : - 1 ], t [ 1 :])]
-
-print ( sum ( pu ))
-print ( sum ( pl ))
-print ( sum ( pb ))
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 5 languages C++ Go Kotlin Lua Python
t = input ()
+
+
+def u ( pos , preference ):
+ if pos == preference == "U" :
+ return 0
+ elif pos == preference == "D" :
+ return 1
+ elif pos == "U" and preference == "D" :
+ return 2
+ else :
+ return 1
+
+
+def l ( pos , preference ):
+ if pos == preference == "U" :
+ return 1
+ elif pos == preference == "D" :
+ return 0
+ elif pos == "U" and preference == "D" :
+ return 1
+ else :
+ return 2
+
+
+def b ( pos , preference ):
+ if pos == preference :
+ return 0
+ else :
+ return 1
+
+
+pu = [ u ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "U" * ( len ( t ) - 2 ), t [ 1 :])]
+pl = [ l ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "D" * ( len ( t ) - 2 ), t [ 1 :])]
+pb = [ b ( pos , preference ) for pos , preference in zip ( t [ 0 ] + t [ 1 : - 1 ], t [ 1 :])]
+
+print ( sum ( pu ))
+print ( sum ( pl ))
+print ( sum ( pb ))
+
Solution in Python Solution in Python Solutions in 5 languages Solutions in 2 languages Solution in Python Solutions in 2 languages Lua Python
k = [
- "qwertyuiop" ,
- "asdfghjkl" ,
- "zxcvbnm" ,
-]
-
-
-def d ( a , b ):
- for r1 in range ( 3 ):
- if a in k [ r1 ]:
- c1 = k [ r1 ] . index ( a )
- break
- for r2 in range ( 3 ):
- if b in k [ r2 ]:
- c2 = k [ r2 ] . index ( b )
- break
-
- return abs ( c1 - c2 ) + abs ( r1 - r2 )
-
-
-for _ in range ( int ( input ())):
- x , n = input () . split ()
- n , w = int ( n ), []
-
- for _ in range ( n ):
- y = input ()
- dist = sum ([ d ( a , b ) for a , b in zip ( list ( x ), list ( y ))])
- w . append ([ y , dist ])
-
- print ( " \n " . join ([ f " { k } { v } " for k , v in sorted ( w , key = lambda k : ( k [ 1 ], k [ 0 ]))]))
-
Solution in Python Solutions in 2 languages Solutions in 2 languages Solution in Python Python
k = [
+ "qwertyuiop" ,
+ "asdfghjkl" ,
+ "zxcvbnm" ,
+]
+
+
+def d ( a , b ):
+ for r1 in range ( 3 ):
+ if a in k [ r1 ]:
+ c1 = k [ r1 ] . index ( a )
+ break
+ for r2 in range ( 3 ):
+ if b in k [ r2 ]:
+ c2 = k [ r2 ] . index ( b )
+ break
+
+ return abs ( c1 - c2 ) + abs ( r1 - r2 )
+
+
+for _ in range ( int ( input ())):
+ x , n = input () . split ()
+ n , w = int ( n ), []
+
+ for _ in range ( n ):
+ y = input ()
+ dist = sum ([ d ( a , b ) for a , b in zip ( list ( x ), list ( y ))])
+ w . append ([ y , dist ])
+
+ print ( " \n " . join ([ f " { k } { v } " for k , v in sorted ( w , key = lambda k : ( k [ 1 ], k [ 0 ]))]))
+
Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solutions in 2 languages Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
d , a , b , h = io.read ( "*n" , "*n" , "*n" , "*n" )
+m = math.pi * d * d / 4
+t = ( a + b ) * h / 2
+if m == t then
+ print ( 'Jafn storar!' )
+elseif m > t then
+ print ( 'Mahjong!' )
+else
+ print ( 'Trapizza!' )
+end
+
from operator import add , mul , sub , truediv
+14
from math import pi
-a , b , c = [ int ( d ) for d in input () . split ()]
-ops = {
- "+" : add ,
- "-" : sub ,
- "*" : mul ,
- "/" : truediv ,
-}
-
-for op , func in ops . items ():
- if a == func ( b , c ):
- print ( f " { a } = { b }{ op }{ c } " )
- break
- if func ( a , b ) == c :
- print ( f " { a }{ op }{ b } = { c } " )
-
Solutions in 5 languages Solution in Python Solution in Python Python
from operator import add , mul , sub , truediv
-import "fmt"
-
-func main () {
- var a , b int
- fmt . Scan ( & a )
- fmt . Scan ( & b )
- fmt . Println ( float32 ( a ) * float32 ( b ) / 2 )
-}
-
1
+a , b , c = [ int ( d ) for d in input () . split ()]
+ops = {
+ "+" : add ,
+ "-" : sub ,
+ "*" : mul ,
+ "/" : truediv ,
+}
+
+for op , func in ops . items ():
+ if a == func ( b , c ):
+ print ( f " { a } = { b }{ op }{ c } " )
+ break
+ if func ( a , b ) == c :
+ print ( f " { a }{ op }{ b } = { c } " )
+
Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solutions in 5 languages Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
participants = int ( input ())
+10
import math
-vaccinated = 0
-control = 0
-infected_control_a = 0
-infected_vaccinated_a = 0
-infected_control_b = 0
-infected_vaccinated_b = 0
-infected_control_c = 0
-infected_vaccinated_c = 0
-
-for p in range ( participants ):
- record = input ()
- v , a , b , c = list ( record )
-
- if v == "N" :
- control += 1
- else :
- vaccinated += 1
-
- if a == "Y" :
- if v == "N" :
- infected_control_a += 1
- else :
- infected_vaccinated_a += 1
-
- if b == "Y" :
- if v == "N" :
- infected_control_b += 1
- else :
- infected_vaccinated_b += 1
-
- if c == "Y" :
- if v == "N" :
- infected_control_c += 1
- else :
- infected_vaccinated_c += 1
-
-
-def get_vaccine_efficacy ( infected_vaccinated , vaccinated , infected_control , control ):
- infection_rate_vaccinated = infected_vaccinated / vaccinated
- infection_rate_control = infected_control / control
- return 1 - infection_rate_vaccinated / infection_rate_control
-
-
-vaccine_efficacy = [
- get_vaccine_efficacy (
- infected_vaccinated_a ,
- vaccinated ,
- infected_control_a ,
- control ,
- ),
- get_vaccine_efficacy (
- infected_vaccinated_b ,
- vaccinated ,
- infected_control_b ,
- control ,
- ),
- get_vaccine_efficacy (
- infected_vaccinated_c ,
- vaccinated ,
- infected_control_c ,
- control ,
- ),
-]
-
-for value in vaccine_efficacy :
- if value <= 0 :
- print ( "Not Effective" )
- else :
- print ( f " { value * 100 : .6f } " )
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
participants = int ( input ())
+
+vaccinated = 0
+control = 0
+infected_control_a = 0
+infected_vaccinated_a = 0
+infected_control_b = 0
+infected_vaccinated_b = 0
+infected_control_c = 0
+infected_vaccinated_c = 0
+
+for p in range ( participants ):
+ record = input ()
+ v , a , b , c = list ( record )
+
+ if v == "N" :
+ control += 1
+ else :
+ vaccinated += 1
+
+ if a == "Y" :
+ if v == "N" :
+ infected_control_a += 1
+ else :
+ infected_vaccinated_a += 1
+
+ if b == "Y" :
+ if v == "N" :
+ infected_control_b += 1
+ else :
+ infected_vaccinated_b += 1
+
+ if c == "Y" :
+ if v == "N" :
+ infected_control_c += 1
+ else :
+ infected_vaccinated_c += 1
+
+
+def get_vaccine_efficacy ( infected_vaccinated , vaccinated , infected_control , control ):
+ infection_rate_vaccinated = infected_vaccinated / vaccinated
+ infection_rate_control = infected_control / control
+ return 1 - infection_rate_vaccinated / infection_rate_control
+
+
+vaccine_efficacy = [
+ get_vaccine_efficacy (
+ infected_vaccinated_a ,
+ vaccinated ,
+ infected_control_a ,
+ control ,
+ ),
+ get_vaccine_efficacy (
+ infected_vaccinated_b ,
+ vaccinated ,
+ infected_control_b ,
+ control ,
+ ),
+ get_vaccine_efficacy (
+ infected_vaccinated_c ,
+ vaccinated ,
+ infected_control_c ,
+ control ,
+ ),
+]
+
+for value in vaccine_efficacy :
+ if value <= 0 :
+ print ( "Not Effective" )
+ else :
+ print ( f " { value * 100 : .6f } " )
+
Solution in Python Solution in C++ Solution in Python Solution in Python Solution in Python Solution in Python Solution in C++ Solution in Python Solution in Python Solutions in 9 languages Solution in Python Solution in Python Solutions in 9 languages Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
mapping = {
- # row 1
- "1" : "`" ,
- "2" : "1" ,
- "3" : "2" ,
- "4" : "3" ,
- "5" : "4" ,
- "6" : "5" ,
- "7" : "6" ,
- "8" : "7" ,
- "9" : "8" ,
- "0" : "9" ,
- "-" : "0" ,
- "=" : "-" ,
- # row 2
- "W" : "Q" ,
- "E" : "W" ,
- "R" : "E" ,
- "T" : "R" ,
- "Y" : "T" ,
- "U" : "Y" ,
- "I" : "U" ,
- "O" : "I" ,
- "P" : "O" ,
- "[" : "P" ,
- "]" : "[" ,
- " \\ " : "]" ,
- # row 3
- "S" : "A" ,
- "D" : "S" ,
- "F" : "D" ,
- "G" : "F" ,
- "H" : "G" ,
- "J" : "H" ,
- "K" : "J" ,
- "L" : "K" ,
- ";" : "L" ,
- "'" : ";" ,
- # row 4
- "X" : "Z" ,
- "C" : "X" ,
- "V" : "C" ,
- "B" : "V" ,
- "N" : "B" ,
- "M" : "N" ,
- "," : "M" ,
- "." : "," ,
- "/" : "." ,
- " " : " " ,
-}
-
-while True :
- try :
- s = input ()
- except :
- break
- print ( "" . join ([ mapping [ c ] for c in s ]))
-
Solution in Python Solution in Python Solutions in 6 languages Solution in Python Python
#include <iostream>
-
-using namespace std ;
-
-int main ()
-{
- int a , b ;
- cin >> a >> b ;
- int ans = ( a > b ) ? 1 : 0 ;
- cout << ans << endl ;
- return 0 ;
-}
-
mapping = {
+ # row 1
+ "1" : "`" ,
+ "2" : "1" ,
+ "3" : "2" ,
+ "4" : "3" ,
+ "5" : "4" ,
+ "6" : "5" ,
+ "7" : "6" ,
+ "8" : "7" ,
+ "9" : "8" ,
+ "0" : "9" ,
+ "-" : "0" ,
+ "=" : "-" ,
+ # row 2
+ "W" : "Q" ,
+ "E" : "W" ,
+ "R" : "E" ,
+ "T" : "R" ,
+ "Y" : "T" ,
+ "U" : "Y" ,
+ "I" : "U" ,
+ "O" : "I" ,
+ "P" : "O" ,
+ "[" : "P" ,
+ "]" : "[" ,
+ " \\ " : "]" ,
+ # row 3
+ "S" : "A" ,
+ "D" : "S" ,
+ "F" : "D" ,
+ "G" : "F" ,
+ "H" : "G" ,
+ "J" : "H" ,
+ "K" : "J" ,
+ "L" : "K" ,
+ ";" : "L" ,
+ "'" : ";" ,
+ # row 4
+ "X" : "Z" ,
+ "C" : "X" ,
+ "V" : "C" ,
+ "B" : "V" ,
+ "N" : "B" ,
+ "M" : "N" ,
+ "," : "M" ,
+ "." : "," ,
+ "/" : "." ,
+ " " : " " ,
+}
+
+while True :
+ try :
+ s = input ()
+ except :
+ break
+ print ( "" . join ([ mapping [ c ] for c in s ]))
+
Solution in Python Solutions in 6 languages Solutions in 2 languages Lua Python
package main
+
+import "fmt"
+
+func main () {
+ var a , b int
+ fmt . Scan ( & a )
+ fmt . Scan ( & b )
+ if a > b {
+ fmt . Println ( 1 )
+ } else {
+ fmt . Println ( 0 )
+ }
+}
+
import java.util.Scanner ;
+
+class WhichisGreater {
+ public static void main ( String [] args ) {
+ Scanner s = new Scanner ( System . in );
+ int a = s . nextInt ();
+ int b = s . nextInt ();
+ if ( a > b ){
+ System . out . println ( 1 );
+ } else {
+ System . out . println ( 0 );
+ }
+ }
+}
+
const readline = require ( "readline" );
+const rl = readline . createInterface ( process . stdin , process . stdout );
+
+rl . question ( "" , ( line ) => {
+ [ a , b ] = line
+ . trim ()
+ . split ( " " )
+ . map (( e ) => parseInt ( e ));
+ if ( a > b ) {
+ console . log ( 1 );
+ } else {
+ console . log ( 0 );
+ }
+});
+
n , k = io.read ( "*n" , "*n" )
-if math.log ( n , 2 ) <= k then
- print ( "Your wish is granted!" )
+6
a , b = io.read ( "*n" , "*n" )
+if a > b then
+ print ( 1 )
else
- print ( "You will become a flying monkey!" )
+ print ( 0 )
end
import math
-
-n , k = [ int ( d ) for d in input () . split ()]
-ans = math . log ( n , 2 ) <= k
-if ans :
- print ( "Your wish is granted!" )
-else :
- print ( "You will become a flying monkey!" )
-
Solution in Python Python
mapping = {
- 0 : "zero" ,
- 1 : "one" ,
- 2 : "two" ,
- 3 : "three" ,
- 4 : "four" ,
- 5 : "five" ,
- 6 : "six" ,
- 7 : "seven" ,
- 8 : "eight" ,
- 9 : "nine" ,
- 10 : "ten" ,
- 11 : "eleven" ,
- 12 : "twelve" ,
-}
-
-
-def f ( d ):
- if d < 13 :
- return mapping [ d ]
-
- ones = d % 10
- if d < 20 :
- return { 3 : "thir" , 5 : "fif" , 8 : "eigh" } . get ( ones , mapping [ ones ]) + "teen"
-
- tens = d // 10
- return (
- { 2 : "twen" , 3 : "thir" , 4 : "for" , 5 : "fif" , 8 : "eigh" } . get ( tens , mapping [ tens ])
- + "ty"
- + ( "-" + mapping [ ones ] if ones else "" )
- )
-
-
-def t ( w ):
- if w . isdigit ():
- return f ( int ( w ))
- else :
- return w
-
-
-while True :
- try :
- words = input ()
- except :
- break
- print ( " " . join ([ t ( w ) for w in words . split ()]))
-
Solution in Python Solution in Python Solutions in 2 languages Solution in Python Python
a , b = input (), input ()
-size = max ( len ( a ), len ( b ))
-
-a = [ int ( d ) for d in a . zfill ( size )]
-b = [ int ( d ) for d in b . zfill ( size )]
-
-ans_a = [ d1 for d1 , d2 in zip ( a , b ) if d1 >= d2 ]
-ans_b = [ d2 for d1 , d2 in zip ( a , b ) if d2 >= d1 ]
-
-
-def f ( ans ):
- if not ans :
- return "YODA"
- else :
- return int ( "" . join ([ str ( d ) for d in ans ]))
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
mapping = {
+ 0 : "zero" ,
+ 1 : "one" ,
+ 2 : "two" ,
+ 3 : "three" ,
+ 4 : "four" ,
+ 5 : "five" ,
+ 6 : "six" ,
+ 7 : "seven" ,
+ 8 : "eight" ,
+ 9 : "nine" ,
+ 10 : "ten" ,
+ 11 : "eleven" ,
+ 12 : "twelve" ,
+}
-print ( f ( ans_a ))
-print ( f ( ans_b ))
-
Solution in Python Python
l , d , x = input (), input (), input ()
-l , d , x = int ( l ), int ( d ), int ( x )
-
-for i in range ( l , d + 1 ):
- if sum ([ int ( d ) for d in str ( i )]) == x :
- print ( i )
- break
-
-for i in range ( d , l - 1 , - 1 ):
- if sum ([ int ( d ) for d in str ( i )]) == x :
- print ( i )
- break
-
Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Python
l , d , x = input (), input (), input ()
+l , d , x = int ( l ), int ( d ), int ( x )
+
+for i in range ( l , d + 1 ):
+ if sum ([ int ( d ) for d in str ( i )]) == x :
+ print ( i )
+ break
+
+for i in range ( d , l - 1 , - 1 ):
+ if sum ([ int ( d ) for d in str ( i )]) == x :
+ print ( i )
+ break
+
Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Back to top