Solution of 12068 - Harmonic Mean

Problem Description
source:https://uva.onlinejudge.org/external/120/12068.html

Input 

The first line of the input file contains an integer S (0 < S < 501), which indicates how many sets of inputs are there. Each of the next S lines contains one set of input. The description of each set is given below: Each set starts with an integer N (0 < N < 9), which indicates how many numbers are there in this set. This number is followed by N integers a1, a2, a3 . . . aN−1, aN (0 < ai < 101). 

Algorithm of 12043 - Dvisor

Problem Description Link
Algorithm:
In this problem if you use more loop in main program to determine the number of divisor and sum of divisor may be you get time limit exit .
so before test case you must generate two array for divisor and sum_of_divisor and and finally use a loop l
i=a to b and check that if any value i mod k is zero then add div+=divisor[i] and sum+=sum_of_divisor[i];
To generate divisor[] and sum_of_divisor[] you can use siv method
that method is bellow :
at first you must set each element 1 in divisor[] and sum_of_divisor[] after then
image

Solution of 12043 - Dvisor

Problem Description
source:https://uva.onlinejudge.org/external/120/12043.html


Let us define the functions d(n) and σ(n) as 
d(n) = number of divisors of n 
σ(n) = summation of divisors of n 

Here divisors of n include both 1 and n. For example divisors of 6 are 1, 2, 3 and 6. So d(6) = 4 and σ(n) = 12. 
Now let us define two more function g(a, b, k) and h(a, b, k) as 

g(a, b, k) = ∑ i d(i) 
h(a, b, k) = ∑ i σ(i) 

Where a ≤ i ≤ b and i is divisible by k. 

image

Solution of 12015 - Google is Feeling Lucky

Problem Description
source:https://uva.onlinejudge.org/external/120/12015.html

Google is one of the most famous Internet search engines which hosts and develops a number of Internetbased services and products. On its search engine website, an interesting button ‘I’m feeling lucky’ attracts our eyes. This feature could allow the user skip the search result page and goes directly to the first ranked page. Amazing! It saves a lot of time. The question is, when one types some keywords and presses ‘I’m feeling lucky’ button, which web page will appear? Google does a lot and comes up with excellent approaches to deal with it. In this simplified problem, let us just consider that Google assigns every web page an integer-valued relevance. The most related page will be chosen. If there is a tie, all the pages with the highest relevance are possible to be chosen. Your task is simple, given 10 web pages and their relevance. Just pick out all the possible candidates which will be served to the user when ‘I’m feeling lucky’.

Input 

The input contains multiple test cases. The number of test cases T is in the first line of the input file. For each test case, there are 10 lines, describing the web page and the relevance. Each line contains a character string without any blank characters denoting the URL of this web page and an integer Vi denoting the relevance of this web page. The length of the URL is between 1 and 100 inclusively. (1 ≤ Vi ≤ 100) 

Output 

For each test case, output several lines which are the URLs of the web pages which are possible to be chosen. The order of the URLs is the same as the input. Please look at the sample output for further information of output format.

Sample Input


www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 10 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
www.university.edu.cn 9 
acm.university.edu.cn 10 
www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 11 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
acm.university.edu.cn 9 
acm.university.edu.cn 10 

Sample Output 

Case #1: www.alibaba.com www.bad.com acm.university.edu.cn 
Case #2: www.alibaba.com

Solution
#include<stdio.h>

int main()
{
    int t, i, j, k, max, value[15];
    char url[12][105];
    while(scanf("%d",&t)==1)
    {
        for(i=1;i<=t;i++)
        {
            max=0;
            for(j=1;j<=10;j++)
            {
                scanf("%s%d",&url[j], &value[j]);
                if(value[j]>max)
                    max=value[j];
            }
            printf("Case #%d:\n",i);
            for(k=1;k<=10;k++)
            {
                if(max==value[k])
                    printf("%s\n",url[k]);
            }
        }
    }
    return 0;
}
image

Solution of 11995 - I Can Guess the Data Structure!

Problem Description
source:https://uva.onlinejudge.org/external/119/p11995.pdf

There is a bag-like data structure, supporting two operations: 

1 x      Throw an element x into the bag. 
2         Take out an element from the bag. 

Given a sequence of operations with return values, you’re going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine! 

Algorithm of 11995 - I Can Guess the Data Structure!

Problem Description Link
Algorithm:
for this problem n=number of line x=element  you can use STL stack , queue, priority_queue
and when get 1 insert data each STL and increase  value for each STL variable(i.e s, q,p)
when get 2 chaeck
    1. for stack check stack not empty and stack top element = x 
        if condition true the pop from stack.
    2. for que  check queue not empty and queue front = x
        if condition true the pop from queue.
    3. for priority queue check priority_queue not empty and  priority_queue top=x
        if condition true the pop from priority_queue.
for each pop increase value that data(ie. s for stack pop ..)
image

Solution of 11984 - A Change in Thermal Unit

Problem Description
source:https://uva.onlinejudge.org/external/119/p11984.html

Measuring temperature and temperature differences are common task in many research and applications. Unfortunately, there exists more than one unit of measuring temperatures. This introduces a lot of confusion at times. Two popular units of measurements are Celsius(C) and Fahrenheit (F). The conversion of F from C is given by the formula

                             F = (9 / 5) * C + 32

In this problem, you will be given an initial temperature in C and an increase in temperature in F. You would have to calculate the new temperature in C.

image

Solution of 11970 - Lucky Numbers

Problem Description
source:https://uva.onlinejudge.org/external/119/p11970.html

Every person has its own numbers that he considers lucky. Usually the numbers are fixed like 3 or 7 and do not depend on anything. This lucky number model seems to be very primitive for John, so he decided to upgrade it for his own use. Maybe more complex model will bring more luck to him? John has added a dependency for lucky numbers on specific integer N (for example N can be ordinal number of day in year or some other meaning). For each N John considers some number X lucky if and only if fraction X/√( N − X) value is integer and greater than zero. 

Input 

The number of tests T (T ≤ 100) is given on the first line. T lines follow, each of them contains one integer N (1 ≤ N ≤ 109 ) described above. 

image

Solution of 11965 - Extra Spaces

Problem Description
source:https://uva.onlinejudge.org/external/119/p11965.html

In programming multiple whitespaces are used to only to make code more readable, so mostly all programming languages totally ignore multiple spaces in code (except for some esoteric ones). In general there are different types of whitespace characters: space itself, tabs, newline symbol, various control characters, etc. Tabs and spaces bring one or the biggest holywar to a programmers world as there is no common rule what to use for code indentation — tab or space characters. In this holywar you stand for tab side and your project code convention requires to use only them for code indentation. However you have recently spotted that someone is using space characters instead of it. Four spaces and tab character look the same in our text editor, so you have decided to write a parser that will change all consequent space characters to one. After that you would be able to determine amount of corrupted code.

image

Solution of 11946 - Code Number

Problem Description
source:https://uva.onlinejudge.org/external/119/p11946.html

Adrian and Maria are relatives that live in different towns. As they inhabit a rural area, it is very difficult for them to keep in touch. One way they found to overcome their communication problem was to send a line through their parents that used to visit each other.

 The point is that Adrian and Maria did not want that their parents read their messages, and they decided to create a secret code for the messages. The code is not very sophisticated, but you should keep in mind Adrian and Maria are just children. 

In general, the meaning of a message is based on changing some letters by numbers. Each message is composed by several lines using uppercase letters of the English alphabet, space and punctuation symbols: dot and comma. The letters that are changed by numbers can be seen in the following example; this change is the same for all messages between Adrian and Maria. 

Message in “Code Number”:

image