Jocelyn’s skill is to write stories of letters. But she finds it very boring to write the story, and after three hours of work, Jocelyn realizes that what she wrote is full of A and B letters, and decides that the story will not end on time. So having a little fun with it, at least counting the bubbly words.
Now Jocelyn connects the same pair of letters (A with A, B, and B) by drawing lines on the word. A given word bubble, if it is possible to combine each letter exactly with another letter so that it does not exceed two letters.
Help Jocelyn figure out how many words are bubbly.
Input:
The first input contains the positive integer M, the number of words.
Each of the following M lines contains a single word consisting of letters A and B
Output:
Output must contain the number of bubbly words
Example:
A B A B
First A indexed in 1 and another A letter indexed in 3 rd position.
First B indexed in 2 and another B letter indexed in 4 th position.
if you draw an arc between A & A, B & B, then the arc will intersect each other.So it is not a bubbly word
#include <stdio.h> #include <string.h> struct letters{char x[1000001];}; char stack[1000001]; int top=-1; void pop(){top--;} void push(char n) { top++; stack[top]=n; } int sizeOfStack(){return top+1;} int main() { struct letters story; int n,i,words=0; scanf("%d",&n); while(n--) { scanf("%s",story.x); for(i=0;i<strlen(story.x);i++) { if(top==-1 || stack[top]!=story.x[i]) push(story.x[i]); else pop(); } if(sizeOfStack()==0) words++; top=-1; } printf("%d",words); return 0; }
INPUT_1:
3
ABAB
AABB
ABBA
OUTPUT:
2
INPUT_2:
2
ABAB
AABB
OUTPUT:
1
ILLUSTRATION
Morae Q!
- Conversion of days into year, weeks and days.
- Find if the number is a perfect number or not.
- Compute conversion of Binary to Octal.
- Return the sum of digits in a number.
- Find if a word exists or not in a sentence.
- Convert Numbers into Words.
- Read a word if it consists only of the letters known.
- Check if the string is a dynamic string or not.
- Convert all Uppercase letters to Lowercase and vice-versa.
- Change the string such that there are no matching adjacent characters.
- Find the number of sub-strings which start and end both in 1.
- Find the start and end index of unsorted sub-array.
- Find the maximum number of pairs that can be formed.
- Figure out the number of bubbly words present.
- Check if a string is lapindrome or not even with a middle character.
- Seating layout in a triangular shaped class according to the number of rows.
- Find and Sort a sub-array which makes whole array sorted.
- Seating layout according to the number of rows.
- Find the final states of the bulbs.
- Check if reversing sub array makes the array sorted.