Posts

Showing posts from August, 2019

Longest Palindrome Length

The program must accept a string  S  as the input. The program must print the length of the longest palindrome that can be formed with the consonants in the string S as the output. Note : At least one consonant must be present in the string S. The string S contains only lower case alphabets. Boundary Condition(s): 1 <= Length of S <= 10^4 Input Format: The first line contains the string S. Output Format: The first line contains the length of the longest palindrome in the string S. Example Input/Output 1: Input: abcdeedb Output: 5 Explanation: The longest palindrome can be formed with bbddc (The order can be any but the length is 5). Example Input/Output 2: Input: racecar Output: 4 Solution:- #include<stdio.h> #include <stdlib.h> int main() {     char str[1000];     scanf("%s",str);     int hash[26]={0};     int count=0,c2=0;          int len=strlen(str);     for(int i=0;i<len;i++)     {         hash[str[i]-'a'

Sort the String Values Based on Length

The program must accept  N  string values as the input. The program must sort the string values based on the length of each string value in increasing order. Then the program must print the sorted string values as the output. Note : Each of the string values has a different length. Boundary Condition(s): 1 <= N <= 100 1 <= Length of each string value <= 100 Input Format: The first line contains the integer N. The next N lines contain the string value in each line. Output Format: The first N lines contain the sorted string values. Example Input/Output 1: Input: 4 lemon embezzling banana ant Output: ant lemon banana embezzling Explanation: The length of the string  lemon  is  5 . The length of the string  embezzling  is  10 . The length of the string  banana  is  6 . The length of the string  ant  is  3 . After sorting the string values based on their length are  ant ,  lemon ,  banana ,  embezzling . Hence the output is  ant lemon banana embezzling Example

Even Sum of Unit Digit and Tenth Digit

The program must accept two integers  X  and  Y  as the input. The program must print the integers having the sum of the tenth digit and unit digit as even from X to Y as the output. Boundary Condition(s): 10 <= X, Y <= 10^8 Input Format: The first line contains the value of X and Y separated by a space. Output Format: The first line contains the integers having the sum of the tenth digit and unit digit as even separated by space(s) Example Input/Output 1: Input: 10 15 Output: 11 13 15 Explanation: The integers from 10 to 15 are 10, 11, 12, 13, 14 and 15. The integers 11, 13 and 15 have the sum of the last two digits as even. Hence 11 13 15 are printed. Example Input/Output 2: Input: 20 30 Output: 20 22 24 26 28 Solution :- #include<stdio.h> #include <stdlib.h> int main() {     int x,y;     scanf("%d %d",&x,&y);          for(int i=x;i<=y;i++)     {         int un=i%10;         int hn=(i/10)%10;      

Twisted Prime

The program must accept an integer  N  as the input. The program must print  YES  if N is a twisted prime number. Else the program must print  NO  as the output. A number is said to be twisted prime if it is a prime number and reverse of the number is also a prime number. Boundary Condition(s): 1 <= N <= 10^16 Input Format: The first line contains the value of N. Output Format: The first line contains either YES or NO. Example Input/Output 1: Input: 97 Output: YES Explanation: 97  is a prime number. The reverse of 97 is 79. So  79  is also a prime number. Hence the output is YES Example Input/Output 2: Input: 34 Output: NO Solution :- #include<stdio.h> #include <stdlib.h> int isprime(int  n) {     for(int i=2;i<=n/2;i++)     {         if(n%i==0)         return 0;     }          return 1; } int main() {     int n;     int x=0,y=0;     int f1=0,f2=0;     scanf("%d",&n);     x=n;     

Numbers and Asterisks - V Pattern

The program must accept an integer  N  as the input. The program must print the desired pattern as shown in the Example Input/Output section. Boundary Condition(s): 2 <= N <= 100 Input Format: The first line contains the value of N. Output Format: The lines containing the desired pattern as shown in the Example Input/Output section. Example Input/Output 1: Input: 3 Output: 1*2*3 *1*2* **1** Example Input/Output 2: Input: 6 Output: 1*2*3*4*5*6 *1*2*3*4*5* **1*2*3*4** ***1*2*3*** ****1*2**** *****1***** Solution :- #include<stdio.h> #include <stdlib.h> int main() {     int n;     scanf("%d",&n);     int x=n;          int len=n+(n-1);          for(int i=1;i<=n;i++)     {         for(int x=1;x<i;x++)         {             printf("*");         }         for(int j=1;j<=n+1-i;j++)         {             if(j==x)             printf("%d",j);             else          

CopyAll and Paste Operations

The program must accept an integer  N  and a string  S  as the input. The program must perform two operations they are copyAll and paste repeatedly for N times. Each time when the copyAll operation is performed, all the characters in the string S are copied. The paste operation pastes the last copied characters at the end of the string S. Finally, the program must print the number of characters present in the string S after repeating the two operations for N times. Boundary Condition(s): 1 <= N <= 100 1 <= Length of S <= 100 Input Format: The first line contains the integer N and the string S separated by a space Output Format: The first line contains the length of the final string. Example Input/Output 1: Input: 2 abc Output: 12 Explanation: Initially, the string S contains  abc. The first time copyAll operation is performed. So abc is copied.  Then the paste operation is performed. Now, the string contains the characters  abcabc . The second time copyAll ope

Spilt Array - Equal Sum

The program must accept an integer array of size N as the input. The program must print  YES  if it is possible to split the array into two sides so that the sum of the integers on one side is equal to the sum of the integers on the other side. Else the program must print  NO  as the output. Boundary Condition(s): 2 <= N <= 100 1 <= Each integer value <= 10^5 Input Format: The first line contains the value of N. The second line contains N integers separated by a space. Output Format: The first line contains either YES or NO. Example Input/Output 1: Input: 5 5 4 7 1 1 Output: YES Explanation: The array can be split as "5 4" and "7 1 1". The sum of the integers on one side is 9 (5 + 4). The sum of the integers on the other side is 9 (7 + 1 + 1). Here the sum of the integers on one side is equal to the sum of the integers on the other side. Hence the output is YES Example Input/Output 2: Input: 6 2 6 8 3 4 1 Output: NO

Reframe with Hundredth Digit

The program must accept an integer  N  and a sum value  X  (sum of unit digit, tenth digit and hundredth digit of N) as the input. The hundredth digit is removed from N. The program must find the hundredth digit and print N by reframing it as the output. Boundary Condition(s): 1 <= N <= 10^8 1 <= X <= 27 Input Format: The first line contains the two integer values N and X separated by a space. Output Format: The first line contains the reframed N. Example Input/Output 1: Input: 1269 20 Output: 12569 Explanation: The sum of the last two digits in 1269 is 15. The difference between 20 and 15 is  5  (20-15). So the hundredth digit is 5. After reframing the N is 12569. Hence the output is  12569 .   Example Input/Output 2: Input: 43217 9 Output: 432117 Solution:- #include<stdio.h> #include <stdlib.h> int main() {     int a,b;     scanf("%d %d",&a,&b);          int ud=a%10;     int td=(a/10)%10;         

First X Consonants

The program must accept a string S and an integer X as the input. The program must print the first X consonants in the string S as the output. If the number of consonants in the string S is less than X then the program must print -1 as the output. Note :  The string S contains only alphabets. Boundary Condition(s): 1 <= Length of S <= 100 1 <= X <= Length of S Input Format: The first line contains the string S. The second line contains the value of X. Output Format: The first line contains either the first X consonants in S or -1. Example Input/Output 1: Input: SkillRack 5 Output: SkllR Explanation: The first 5 consonants in the string "SkillRack" are S, k, l, l and R. So they are printed as the output. Example Input/Output 2: Input: Dengue 6 Output: -1 Solution :- #include<stdio.h> #include <stdlib.h> int isvowel(char ch) {     ch=tolower(ch);          if(ch=='a'||ch=='e'||ch=='i'||ch==&#

Difference - Sum of Odd and Even Digits

Given a maximum of hundred digits as the input. The program must print the difference between the sum of odd and even digits as the output. If the input is not a valid number, then print  Invalid  as the output. Example Input/Output 1: Input: 118745913 Output: 15 Explanation: The sum of odd digits is  27  (1, 1, 7, 5, 9, 1 and 3). The sum of even digits is  12  (8 and 4). So the difference is  27-12 = 15 . Hence the output is 15 Example Input/Output 2: Input: 235468173645 Output: -6 Example Input/Output 3: Input: 76320Afk384 Output: Invalid Note:  The invalid number may contain white spaces. Solution :- #include<stdio.h> int main() {     char str[1000];     scanf("%[^\n]s",str);          int len=strlen(str),flag=0,even=0,odd=0;          for(int i=0;i<len;i++)     {         if(isalpha(str[i]) || str[i]==' ' || isalnum(str[i])==0)         {             flag=1;             break;         }             

String Leaving Characters - Forward

The program must accept a string  S  as the input. The program must print the first character, the third character, the sixth character and so on as the output. Boundary Condition(s): 1 <= Length of S <= 100 Input Format: The first line contains the string S. Output Format: The first line contains the characters of string S as per the given conditions. Example Input/Output 1: Input: abcdefghijklmno Output: acfjo Explanation: 1 st  character is  a . 3 rd  character is  c . 6 th  character is  f . 10 th  character is  j . 15 th  character is  o . So these characters are printed as the output. Example Input/Output 2: Input: northeastwestsouth Output: nrewo Solution :- #include<stdio.h> #include <stdlib.h> int main() {     char a[100];     scanf("%s",a);     int x=2;          for(int i=0;i<strlen(a);)     {                  printf("%c",a[i]);         i=i+x;         x++;              }