Balancing Paranthesis

Input: 3 {} {}() {)() Output: Yes Yes No Solution: import java.util.*; public class stackk { public static class stack { int top=-1; char items[] = new char[100]; void push(char x) { items[++top] = x; } char pop() { char element = items[top]; top–; return element; } boolean isEmpty() { if (top == -1) return…

Remove Palindrome from a sentence

Problem statement: Remove all the palindromic words in the given sentence. Input :  he is a good deed in malayalam Output: he is good in he is good public class Removepalindrome { public boolean ispalindrome(String a) { int i,j; boolean flag = true; int l=a.length(); for(j=l-1,i=0;i<(l/2);i++,j–) { if(a.charAt(i)!=a.charAt(j)) flag =false; } return flag; } public static void…

Check a Pattern in a String

  Question: Input: string ring Output: Found Solution: #include<stdio.h> #include<string.h> int main() { char a[10],b[10]; scanf(“%s”,a); scanf(“%s”,b); int i=0,j=0; int flag=1; while(i!=strlen(a)) { if(a[i]==b[j]) { i++; j++; if(j==strlen(b)) { printf(“Found”); flag=0; break; } } else { j=0; i++; } } if(flag==1) printf(“NotFound”); return 0; }

Snake you cant escape from us ;)

#include <stdio.h> #include<string.h> #include <stdlib.h> int  Initial_snake_x=2; int  Initial_snake_y=4; int flag=1; int Food_x,Food_y; int matrix[5][5]; int i,n,j; void choice(); void displaymatrix(); int randomfun() { time_t t; srand((unsigned) time(&t)); return (rand() % 5); } void initialise() { memset(matrix,0,sizeof(matrix)); } int Snake_length(int snake_x_food,int snake_food_y) { //matrix[snake_x_food][snake_food_y]=4; if(matrix[Food_x][Food_y]==matrix[snake_x_food][snake_food_y]) { printf(“Food Captured..Yummyyyy 🙂 🙂 :)\n”); matrix[snake_x_food][snake_food_y]=4; Food_x=randomfun(); Food_y=randomfun(); matrix[Food_x][Food_y]=1;…

assert()

This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution. #include <assert.h> #include <stdio.h> int main() { int a; char str[50]; printf(“Enter an…

Merging two sorted Arrays

Solution: #include <stdio.h> void merge(int [], int, int [], int, int []); int main() { int a[100], b[100], m, n, c, sorted[200]; printf(“Input number of elements in first array\n”); scanf(“%d”, &m); printf(“Input %d integers\n”, m); for (c = 0; c < m; c++) { scanf(“%d”, &a[c]); } printf(“Input number of elements in second array\n”); scanf(“%d”,…

Substring count in a string

#include<stdio.h> #include<string.h> int main() { char s[100]; char *p; char s1[10]; char *q; int i,m,j = 1,l,count = 0; printf(“Enter the text:”); gets(s); printf(“Enter the word you wanna count:”); gets(s1); p = s; q = s1; l = strlen(s); m = strlen(s1); i = 0; while(*(p+i)!=’\0′) { j = 0;m = 1; while(*(p+i) != ‘…

Stair Case

Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example? Input You are given an integer depicting the height of the staircase. Output…

Unique-sum of n digits

#include <stdio.h> #include <stdlib.h> int main(){ int n,i,*ptr,sum=0; printf(“Enter number of elements: “); scanf(“%d”,&n); ptr=(int*)calloc(n,sizeof(int)); if(ptr==NULL) { printf(“Error! memory not allocated.”); exit(0); } printf(“Enter elements of array: “); for(i=0;i<n;++i) { scanf(“%d”,ptr+i); sum+=*(ptr+i); } printf(“Sum=%d”,sum); free(ptr); return 0; }

Find whether an array is subset of another array

Examples: Input: arr1[] = {11, 1, 13, 21, 3, 7}, arr2[] = {11, 3, 7, 1} Output: arr2[] is a subset of arr1[] Input: arr1[] = {1, 2, 3, 4, 5, 6}, arr2[] = {1, 2, 4} Output: arr2[] is a subset of arr1[] Input: arr1[] = {10, 5, 2, 23, 19}, arr2[] = {19,…

Union and Intersection of two sorted arrays

int printUnion(int arr1[], int arr2[], int m, int n) {   int i = 0, j = 0;   while (i < m && j < n)   {     if (arr1[i] < arr2[j])       printf(” %d “, arr1[i++]);     else if (arr2[j] < arr1[i])       printf(” %d “, arr2[j++]);     else     {       printf(” %d “, arr2[j++]);       i++;     }   }   /* Print remaining…

Zumaka Zoooo!!!

Strings are in competition. Be a judge for them to qualify.You are lenient judge. so you will accept small changes that are specified in rule 2 and 3 The rules are simple as follows, 1. “Shortlisted” – if number of each character in the string is equal to its frequency. 2. “Less ‘character’ Shortlisted” –…