1
+ body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}
582 Problems, 825 Solutions, 11 Languages Solution in Python Solution in Python Solution in Python Solutions in 5 languages Solutions in 8 languages Solutions in 3 languages Solution in Python Solution in Python Solutions in 3 languages 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 Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
n = io.read ( "*n" )
-t = 0
-top = 0
-for _ = 1 , n do
- d = io.read ( "*n" )
- if top == 0 or d > top then
- t = t + 1
- end
- top = d
-end
-print ( t )
+
+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 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 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 Solutions in 2 languages Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Lua Python
from operator import add , mul , sub , truediv
-
-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 Solutions in 5 languages C++ Go Java Lua Python
#include <iostream>
+
+using namespace std ;
+
+int main ()
+{
+ int h , b ;
+ cin >> h >> b ;
+ cout << float ( h ) * b / 2 << endl ;
+ return 0 ;
+}
+
package main
+
+import "fmt"
+
+func main () {
+ var a , b int
+ fmt . Scan ( & a )
+ fmt . Scan ( & b )
+ fmt . Println ( float32 ( a ) * float32 ( b ) / 2 )
+}
+
moves = input ()
-ball = [ 1 , 0 , 0 ]
-for move in moves :
- if move == "A" :
- ball [ 0 ], ball [ 1 ] = ball [ 1 ], ball [ 0 ]
- if move == "B" :
- ball [ 1 ], ball [ 2 ] = ball [ 2 ], ball [ 1 ]
- if move == "C" :
- ball [ 0 ], ball [ 2 ] = ball [ 2 ], ball [ 0 ]
-
-if ball [ 0 ]:
- print ( 1 )
-elif ball [ 1 ]:
- print ( 2 )
-else :
- print ( 3 )
-
Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solutions in 5 languages Solution in Python Solution in Python Solution in Python 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 Python
participants = int ( input ())
+19
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 Solution in Python Solution in C++ C++
1
+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 Solution in Python Solutions in 9 languages Solution in C++ Solution in Python 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 Solution in Python Solutions in 3 languages 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 Solution in Python 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 )
- }
-}
-
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
n , k = io.read ( "*n" , "*n" )
-if math.log ( n , 2 ) <= k then
- print ( "Your wish is granted!" )
-else
- print ( "You will become a flying monkey!" )
-end
+12
#include <iostream>
+
+using namespace std ;
+
+int main ()
+{
+ int a , b ;
+ cin >> a >> b ;
+ int ans = ( a > b ) ? 1 : 0 ;
+ cout << ans << endl ;
+ return 0 ;
+}
+
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 );
+ }
+});
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 Solution in Python Solutions in 2 languages 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 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 Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Back to top