Skip to main content

Posts

Showing posts from September, 2020

UVa 10062 - Tell me the frequency Solution

UVa  10062 - Tell me the frequency Description:  Given a line of text you will have to find out the frequencies of the ASCII characters present in it. The  given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with  \n and \r but always keep those out of consideration. Input Several lines of text are given as input. Each line of text is considered as a single input. Maximum  length of each line is 1000. Output Print the ASCII value of the ASCII characters which are present and their frequency according to the  given format below. A blank line should separate each set of output. Print the ASCII characters in the  ascending order of their frequencies. If two characters are present the same time print the information  of the ASCII character with higher ASCII value first. Input is terminated by end of file. Sample Input AAABBC 122333 Sample Output 67 1 66 2 65 3 49 1 50 2 51 3 Solution #include<stdio.h...

UVa 10071 - Back to High School Physics Solution

UVa 10071 - Back to High School Physics Description:  A particle has initial velocity and acceleration. If its velocity after certain time is v then what will its displacement be in twice of that time? Input The input will contain two integers in each line. Each line makes one set of input. These two integers denote the value of v (−100 ≤ v ≤ 100) and t (0 ≤ t ≤ 200) (t means at the time the particle gains that velocity) Output For each line of input print a single integer in one line denoting the displacement in double of that time. Sample Input 0 0 5 12 Sample Output 0 120  Solution #include<stdio.h> int main () { int s,v,t; while( scanf ("%d%d",&v,&t)==2) { s=v*(t*2); printf("%d\n",s); } return 0; } See More Solution: UVa 10062 - Tell me frequency solution UVa 10079 - pizza cutting solutio UVa 10082 - wertyu solution UVa 10050 - Hartals solutions UVa 10038 - Jolly jumpers solution l UVa 100 - 3n + 1 problem solu...

UVa 10079 - Pizza Cutting Solution

UVa 10079 - Pizza Cutting Description:  When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his intelligence allows him to do something at less physical effort, why should he exert more? He also claims that he always uses his brain and tries to do some work at less effort; this is not his laziness, rather this is his intellectual smartness. Once Ivan was asked to cut a pizza into seven pieces to distribute it among his friends. (Size of the pieces may not be the same. In fact, his piece will be larger than the others.) He thought a bit, and came to the conclusion that he can cut it into seven pieces by only three straight cuts through the pizza with a pizza knife. Accordingly, he cut the pizza in the following way (guess which one is Ivan’s piece): One of his friends, who never believed in Ivan’s smartness, was startled at this intelligence. He thought, if Ivan can do it, why can’t my computer? So he tried to do a similar (but not ex...

UVa 10082 - WERTYU Solution

UVa  10082 - WERTYU Description:   A common typing error is to place the  hands on the keyboard one row to the  right of the correct position. So ‘Q’ is  typed as ‘W’ and ‘J’ is typed as ‘K’ and  so on. You are to decode a message typed in this manner. Input Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except  Q, A, Z), or punctuation shown above [except back-quote (‘)]. Keys labelled with words [Tab, BackSp,  Control, etc.] are not represented in the input. Output You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’  keyboard shown above. Spaces in the input should be echoed in the output. Sample Input O S, GOMR YPFSU/ Sample Output I AM FINE TODAY.  Solution #include<stdio.h> int main () { char str[10000], key[]={'`','1','2','3','4','5','6','7','8','9','0', '-','=','...

UVa 10050 - Hartals Solution

UVa  10050 - Hartals Description: A social research organization has determined a simple set of parameters to simulate the behavior of the political parties of our country. One of the parameters is a positive integer h (called the hartal parameter) that denotes the average number of days between two successive hartals (strikes) called by the corresponding party. Though the parameter is far too simple to be flawless, it can still be used to forecast the damages caused by hartals. The following example will give you a clear idea: Consider three political parties. In this problem, given the hartal parameters for several political parties and the value of N, your job is to determine the number of working days we lose in those N days. Input The first line of the input consists of a single integer T giving the number of test cases to follow. The first line of each test case contains an integer N (7 ≤ N ≤ 3650) giving the number of days over which the simulation must be run. The next line...

UVa 10038 - Jolly Jumpers Solution

UVa 10038 - Jolly Jumpers Description:   A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n − 1. For instance, 1 4 2 3 is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper. Input  Each line of input contains an integer n ≤ 3000 followed by n integers representing the sequence. Output  For each line of input, generate a line of output saying ‘Jolly’ or ‘Not jolly’. Solution: #include<stdio.h> #include<stdlib.h> int main () { int n,arr[4000],item[4000],i,j,diff=0; while( scanf ("%d",&n)==1) { for(i=1;i<=n;i++) arr[i]=0; for(i=1;i<=n;i++) scanf("%d",&item[i]); if(n!...

UVa 100 - The 3n+1 problem solution

UVa 100- The 3n+1 problem Description:   Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs. Consider the following algorithm: input n print n if n = 1 then STOP if n is odd then n ←− 3n + 1 else n ←− n/2 GOTO 2  Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1, 000, 000 (and, in fact, for many more numbers than this.) Given an input n, it is possible to determine the number of numbers printed before and including the 1 is printed. For a given n th...