uva online judge self describing sequence problem solution python | uva 10049

The self describing sequence problem  (uva 10049) is also very straight forward and easy programming challenge in competitive programming once understood well. Which can be stated as (from online judge) Solomon Golomb’s self–describing sequence ⟨f(1),f(2),f(3),...⟩ is the only nondecreasing sequence of positive integers with the property that it contains exactly f(k) occurrences of k for each k. A few moments thought reveals that the sequence must begin as follows: n 1 2 3 4 5 6 7 8 9 10 11   12 f(n) 1 2 2 3 3 4 4 4 5 5 5 6 In this problem you are expected to write a program that calculates the value of f(n) given the value of n. Sample Input 100  9999  123456  1000000000  0 Sample Output 21  356  1684  438744 Programming Explanation This is very simple problem states that for given range of n as input (as shown in above image), we have

uva online judge common permutation problem solution python | uva 10252

The common permutation problem (uva 10252) is a simple and words puzzle programming challenge from competitive programming. Which can be stated as (from online judge)

Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.

In this problem, we just have to find matching words in given two strings. After finding, just print them in alphabetical order, thats it.

Sample Input

pretty 
women 
walking 
down 
the 
street

Sample Output

nw 
et

Explanation

We just have to compare two strings and find out common characters, using old school method. Print them in alphabetical order.

Code


Final_answer = []

while(True):
    count = 0
    temp = []
    str1 = str()
    a = list(input())
    try:
        a[0]
    except:
        break
    b = list(input())

    
    for i in a:
        count=0
        for j in b:
            if(i==j):
                count+=1
        if(count>0):
            temp.append(i)

    for i in range(0,len(temp)):
        for j in range(i,len(temp)):
            if(ord(temp[i])<ord(temp[j])):
                a = temp[j]
                temp[j] = temp[i]
                temp[i] = a


    Final_answer.append(str1.join(temp))


for i in Final_answer:
    print(i)


Here, we take two for loops to itterate through every character in string, if character is found repeated then store it in list 'temp'. After, sort list 'temp' in alphabetical order and print it.


Related keywords: common permutation, common permutation uva, common permutation online judge, common permutation solution, common permutation explanation, common permutation python, common permutation programming challenge, uva 10252, uva 10252 solution, common permutation source code.

Comments

Popular posts from this blog

uva online judge vito's family problem solution python | uva 10041

uva online judge australian voting problem solution python | uva 10142