Thursday, May 24, 2018

FCTRL - Factorial : Classical

#The solution in Python 3 is as follows:

def count (x):               #function to count the no. of trailing zeros
    i = 5
    zeros = 0
    while x >= i:
        zeros += x // i
        i *= 5                 
    return zeros
t=int(input())              #No. of test cases 
j=0
while j<t:
    a=int(input())
    print(count(a))
    j+=1


#Visit this link for more info.

#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

STRHH - Half of the half : Basics

#The solution in Python 3 is as follows:

a = []
t = int(input())                     #No. of test cases
i=0
while i<t:
    r = input()
    a.append(r)                      #store the strings in a list
    i+=1
for j in a:
    k=0
    while(k<(len(j)//2)):          #continue loop till half of the string.
        print(j[k],end='')            #Print every second character.
        k+=2
    print()



#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

Wednesday, May 23, 2018

TEST - Life,Universe and Everything : Classical

#The solution in Python 3 is as follows:

n=int(input())
while n!=42:
    print(n)
    n=int(input())


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

FCTRL2 - Small Factorials : Classical

#The solution in Python 3 is as follows:

t = int(input())                      #No.of test cases
i=0
while i<t:
    a=int(input())
    j=1
    fact=1
    while j<=a:
        fact=fact*j                    #compute the factorial
        j+=1
    print(fact) 
    i+=1


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

JULKA - Julka : Classical

#The solution in Python 3 is as follows:

t=10
i=0
while i<t:
    a=int(input())                   #No. of apples both have
    b=int(input())                   #No. of  extra apples Klaudia has
    c=(a-b)//2
    print(b+c)               
    print(c)
    i+=1


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

AE00 - Rectangles : Classical

#The Python 3 solution is as follows:

import math
a=int(input())                               #input the no. of squares
i=1
sum=0                                         #Count the no. of  pairs(m*n)of factors of a
while i<=a:                                 #such that m*n=no.of squares
    n=math.sqrt(i)                        #sqrt is done to rule out n*m case
    j=1
    while j<=n:
        if(i%j==0):                           
            sum+=1
        j+=1 
    i+=1
print(sum)                              #display the no.of pairs=no. of rectangles 


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!

ONP - Transform the expression : Classical

#The Python 3 solution is as follows:

for i in range(int(input())):                               #No. of test cases
    a=input()                                                      #input the actual expression
    o=[]
    s=""
    for j in a:
        if(j== '(' ):                                               #ignore the brackets '(' and ')'
            pass
        elif(ord(j)>=97 and ord(j)<=123):         #consider the lower case letters
            s=s+str(j)
        elif(j== ')' ):
            if(len(o)!=0):
                s=s+str(o.pop())                            #o.pop() removes & returns last item in list
        else:
            o.append(j)                                        #add the operators to the list
    print(s)


#Visit this link for more details.

#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!!

ADDREV : Classical

#The Python 3 solution is as follows:

import sys
t = int(input())
i=0
while i<t:
    a,b = map(int,sys.stdin.readline().split())     #to take both inputs in single line
    c=str(a)                                                         #converting the number into string
    d=str(b)
    e=int(c[::-1])                                                #converting reverse of the string c to int
    f=int(d[::-1])                                               #converting reverse of the string d to int
    s=e+f                                                          #adding the two reverse numbers
    s1=str(s)
    s2=int(s1[::-1])                                           #reverse s and display it
    print(s2)                                                   
    i+=1


#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!