Wednesday 26 April 2017

10.Decipher my Ciphertext

                               Decipher my Ciphertext

In the language of cryptography, ciphertext refers to a message encoded with a particular keyPlaintext refers to the original, unencoded text. In this problem, both the ciphertext and the key are simply strings of upper-case characters. The ciphertext is generated from the plaintext by “adding” corresponding characters of the plaintext and the key together. If the plaintext is shorter than the key, only some of the key will be used. Similarly, if the plaintext is shorter than the key, the key will be used multiple times.

For example, to encode the plaintext “HELLO” with the key “CAT”:
Plaintext: HELLO
Key: CATCA
Ciphertext: KFFOP

And to encode the plaintext “DOG” with the key “FIDO”:
Plaintext: DOG
Key: FID
Ciphertext: JXK

To add two letters together, use the following convention: A=1, B=2, …, Z=26. If the sum of two letters is greater than 26, subtract 26 from the sum. For example: A + E = 1 + 5 = 6 = F, and D + X = 4 + 24 = 28 = 2 = B.

Given a ciphertext/key pair, determine the corresponding plaintext.

Input Format :
Input will consist of pairs of lines, with the first line being the ciphertext and the second line being the key. Both will consist of only uppercase letters.

Output Format:
For each ciphertext/key pair, print the corresponding plaintext message.

Example:

Sample Input:
HELLO
CAT

Sample Output:

KFFOP

code:



9.Fibonacci Roots

                                Fibonacci Roots

The first two terms in the Fibonacci sequence are 0 and 1, respectively, and each subsequent term is the sum of the previous two. Using this definition to calculate the first several terms in the sequence, we get
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Let us define the Fibonacci roots of a positive integer n to be the two smallest consecutive Fibonacci numbers whose sum is greater than or equal to n.

Input Format:
Input consists of a single integer which corresponds to n.
Assumption:
Assume that n is less than or equal to 2000.
Output Format:
Output consists of integers, separated by a space.

Sample Input 1 :
31
Sample Output 1:
13 21

Sample Input 2 :
89
Sample Output 2:

34 55

code:


8.Vowel or Consonant

                            Vowel or Consonant

Write a program to determine whether the input character is a vowel or consonant.

Input and Output Format:

Input consists of a single character.
Output consists of a string --- “Vowel” / “Consonant” / “Not an alphabet”
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:

Enter a character
a
Vowel

Sample Input and Output 2:

Enter a character
Z
Consonant

Sample Input and Output 3:

Enter a character
#

Not an alphabet


code:



Monday 24 April 2017

7.Anagrams

Anagrams

Write a program to find whether the 2 given strings are anagrams or not.
Anagrams are words or phrases made by mixing up the letters of other words or phrases,

Input and Output Format:
Input consists of 2 string. Assume that all characters in the string are lowercase letters or spaces and the maximum length of the string is 100.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:
Enter the first string
anitha
Enter the second string
amphisoft
anitha and amphisoft are not anagrams

Sample Input and Output 2:
Enter the first string
the eyes
Enter the second string
they see
the eyes and they see are anagrams


code:

Sunday 23 April 2017

6.Zero Duplicates

Zero Duplicates

Write a program that will read in a list of numbers and will then print out the same list except numbers that have already been printed will be printed as a zero instead.
Input Format:
Input consists of n+1 integers where n is the number of elements in the list. The first integer corresponds to n. The remaining n integers correspond to the elements in the list.
Assume that the maximum value of n is 100.

Output Format:
Output consists of n integers on separate lines.

code :

5.The Next Palindrome

The Next Palindrome
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K, write the value of the smallest palindrome larger than K to output.
Input
The first line contains an integer, which corresponds to K. Assume that K is less than 200000.
Output
Output consists of a single integer, which corresponds to the smallest palindrome larger than K.
Sample Input 1:
808
Sample Output 1:
818

code:


4.TENNIS COURT

TENNIS COURT


They sent a request to the Chairman and he readily agreed but he asked to do it with minimal expenditure. He gave them square stones.

The tennis court in the college is rectangular in shape of size n*m metres. We need to pave the court with square stones. The square stone is of size a*a.

What is the least number of stones needed to pave the tennis court? It's allowed to cover the surface larger than the Tennis Court, but the court has to be covered. It's not allowed to break the stones. The sides of stones should be parallel to the sides of the court.
Input Format:
Input consists of 3 integers. The first integer corresponds to 'n', the length of the court. The second integer corresponds to 'm', the width of the court. The third integer corresponds to 'a', the side of the square stone.
Output Format:
Output consists of ta single integer k, where k is the least number of stones needed.

code:


3.SMS Language

SMS Language

SMS language or textese (also known as txt-speak, txtese, chatspeak, txt, txtspk, txtk, txto, texting language, txt lingo, SMSish,txtslang,or txt talk) is a term for the abbreviations and slang commonly used with mobile phone text messaging.

Some of the abbreviations used are
  • s for yes
  • u for you
  • 2day for today
  • y for why

Many grandpa's have started sending SMSes to their grand children. But they are not familiar with the SMS lingo.

Can you help them by writing a program that would convert a given text in proper English to SMS lingo? Consider only the 4 wordslisted above.

Input Format:
Input consists of a single string. Assume that the maximum length of the string is 200 and all letters are in lower-case.

Output Format:
Output consists of a single string.

Sample Input 1:
where were you yesterday?

Sample Output 1:
where were u sterday?

Sample Input 2:
why is today a working day for you?

Sample Output 2:
y is 2day a working day for u?

code:




2.ENCODING

 ENCODING

In this program you will be given a letter to encode. The difference here is that different rules are used for different letters and the counting process can cause you to wrap around the alphabet. Using the numerical value of each letter (A=1, B=2, ... Z= 26) the rules are as follows:

If the letter is between the given letters, inclusive:
The number of letters to count is given by:
A–E
Multiply its numerical value by 2
F–J
Divide its numerical value by 3. Multiply the integer remainder by 5
K–O
Divide its numerical value by 4. Multiply the integer remainder by 8.
P–T
Add 10.
U- Z
Find the largest integer factor of its numerical value less than the value itself. Multiply it by 12.

As an example if the letter to encode is a B, the B has a numerical value of 2 and encodes to a  4 and becomes a D, the 4th letter of the alphabet.
The G has a numerical value of 7. It encodes to a 5 and becomes an E.
The numerical value of Z is 26. Its largest factor is 13. You must count 156 (13*12) letters. This has the effect of wrapping around the alphabet 6 complete times and ending at Z. If a numerical value of zero is evaluated print a # symbol.
[Hint: ASCII value of A is 65].
INPUT:
Input consists of an upper case letter.
OUTPUT:
Print the encoded letter it produces.


code:


1. Indian Railway

 Indian Railway – Seating arrangement for Sleeper Class


Write a program to determine the type of berth when the seat/berth number in the train is given.

Input Format:
Input consists of a single integer. Assume that the range of input is between 1 and 72.

Output Format:
Output consists of a single string. [Upper or Middle or Lower or Side Lower or Side Upper]


code :


Stack and Queue / Session XI

Stack 2 : Array Implementation : Push and Pop

Consider implementing a dynamically sized stack using an array.

Create a structure

struct stack
{
int * a;
int top;
int maxSize;
};

The structure stack has a pointer 'a' to a dynamically allocated array (used to hold the contents of the stack), an integer 'maxSize' that holds the size of this array (i.e the maximum number of data that can be held in this array) and an integer 'top' which stores the array index of the top element in the stack.




 Array Implementation answers 
click the link below for code:




Queue 1 : Array Implementation


Consider implementing a fixed size queue of maximum size 5 using an array.

Create a structure

struct queue {
int contents[5];
int front;
int count;
} ;

Note that the array contents holds the contents of the queue and the integer front stores the index of the front element in the queue.

Write a program to implement enQueue and deQueue operation on queue and to display the contents of the queue.

In the initQueue function intialize the value of front and count to 0.
Print the message “Queue is full” in the enQueue function when an attempt is made to insert a data into a full queue.
Print the message “Queue is empty” in the deQueue function and return the value -1000 when an attempt is made to delete data from an empty queue.

Refer function specifications for further details.



code:


#include<stdio.h> #include<string.h>
struct queue {
int contents[5];
int front;
int count;
} ;
void initQueue(struct queue * q);
void enQueue(struct queue * q, int element);
int deQueue(struct queue * q);
void display( struct queue q);
void printMenu();
int main()
{
struct queue p;
int data,ch, data1;
initQueue(&p);
do {
printMenu();
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch) {
case 1:
printf("Enter the element to be inserted/entered\n");
scanf("%d",&data);
enQueue(&p, data);
break;
case 2:
data1 = deQueue(&p);
if(data1 != -1000)
printf("The deleted element is %d\n",data1);
break;
case 3:
printf("The contents of the queue are");
display(p);
printf("\n");
break;
default:
return 0;
}
} while(1);
return 0;
}
void printMenu()
{
printf("Choice 1 : Enter element into Queue\n");
printf("Choice 2 : Delete element from Queue\n");
printf("Choice 3 : Display\n");
printf("Any other choice : Exit\n");
}
void initQueue(struct queue * q)
{
q->front=0;
q->count=0;
}
void enQueue(struct queue * q, int element)
{
int index;
index=(q->count+q->front)%5;
if(index==q->front&&q->count!=0)
printf("Queue is full\n");
else
{
q->count++;
q->contents[index]=element;
}
}
int deQueue(struct queue * q)
{
int elem;
if(q->count==0)
{
printf("Queue is empty\n");
return (-1000);
}
elem=q->contents[q->front];
q->count--;
q->front=(q->front+1)%5;
return elem;
}
void display( struct queue q)
{
int i,index;
if(q.count==0)
printf(" {}");
else
{
for(index=q.front,i=1;i<=q.count;i++,index++)
printf(" %d",q.contents[index%5]);
}
}