Redirected C Folder (#228)
* redirected bad or Good string.cpp * redirected C Algorithms * created readme of c folder * correct URL of linked list and string algorithm * one line space after C titlepull/229/head
parent
0c6d011ab1
commit
390fc888bd
|
@ -0,0 +1,23 @@
|
||||||
|
# C
|
||||||
|
|
||||||
|
## Arrays
|
||||||
|
- [Even and Odd](arrays/even-and-odd.c)
|
||||||
|
- [Unique Elements in an array](arrays/unique-elements-in-an-array.c)
|
||||||
|
|
||||||
|
## Graphs
|
||||||
|
- [Prim's Algorithm](graphs/Prim's-algorithm.c)
|
||||||
|
|
||||||
|
## Linked Lists
|
||||||
|
- [Insert and Delete at Beginning](linked-lists/Insert-and-delete-beginning.c)
|
||||||
|
- [Josephus Problem](linked-lists/josephus-problem.c)
|
||||||
|
|
||||||
|
## Queues
|
||||||
|
- [Double Ended Queue using array](queues/double-ended-queue-using-array.c)
|
||||||
|
|
||||||
|
## Sorting
|
||||||
|
- [Merge Sort](sorting/merge-sort.c)
|
||||||
|
|
||||||
|
## Strings
|
||||||
|
- [Count Words](strings/count-words.c)
|
||||||
|
- [Palindrome](strings/palindrome.c)
|
||||||
|
- [Permutation of String](string/Permutation-of-String.c)
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
Program to check whether a string is bad or good
|
||||||
|
Criteria:
|
||||||
|
1: If a string contain 3 more than three constant or more than 5 vowels continuously than it is a bad string else good
|
||||||
|
2: '?' can be replaced by any alphabets means it can be both constant and vowel
|
||||||
|
*/
|
||||||
|
#include<iostream>
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//Function to check whether the character is not vowel
|
||||||
|
int isVowel(char c)
|
||||||
|
{
|
||||||
|
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Function to check whether the entered string is good or bad
|
||||||
|
int Bad_or_Good(string s1)
|
||||||
|
{
|
||||||
|
// Initializing all variable with 0
|
||||||
|
int vowel=0,res=0,constant=0;
|
||||||
|
// until the i is less than s1 length run the loop
|
||||||
|
for(int i=0; i<s1.length(); i++)
|
||||||
|
{
|
||||||
|
//if i th character of string is vowel
|
||||||
|
if(isVowel(s1[i]))
|
||||||
|
{
|
||||||
|
// assign 0 to constant
|
||||||
|
constant=0;
|
||||||
|
// increment vowel
|
||||||
|
vowel++;
|
||||||
|
// check whether a bad string if yes assign 1 to res and break
|
||||||
|
if(vowel>5)
|
||||||
|
{
|
||||||
|
res=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//assign 0 to res
|
||||||
|
else
|
||||||
|
res=0;
|
||||||
|
}
|
||||||
|
// if s[i]th character is '?'
|
||||||
|
else if(s1[i] == '?')
|
||||||
|
{
|
||||||
|
//add 1 in both constant and vowel
|
||||||
|
constant++;
|
||||||
|
vowel++;
|
||||||
|
// check whether it touch the bad string criteria or not
|
||||||
|
if(constant>3||vowel>5)
|
||||||
|
{
|
||||||
|
res=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else res=0;
|
||||||
|
}
|
||||||
|
// if the s[i]th character is not a vowel nor '?' that means it is a constant
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//assign 0 to vowel and increment constant
|
||||||
|
vowel = 0;
|
||||||
|
constant++;
|
||||||
|
// check whether the string touch the bad string criteria or not
|
||||||
|
if(constant>3)
|
||||||
|
{
|
||||||
|
res=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
res=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//driver code
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int t,res;
|
||||||
|
string s1;
|
||||||
|
cout<<"Enter the number of test case: ";
|
||||||
|
cin>>t;
|
||||||
|
//cleaning buffer and going to a new line
|
||||||
|
cin.ignore(1, '\n');
|
||||||
|
// until t is not equal to 0
|
||||||
|
while(t--)
|
||||||
|
{
|
||||||
|
cout<<"Enter string: ";
|
||||||
|
//taking input
|
||||||
|
getline(cin, s1);
|
||||||
|
//calling Bad_or_Good Function to check whether the string is bad or good
|
||||||
|
res=Bad_or_Good(s1);
|
||||||
|
if(res==1)
|
||||||
|
cout<<0<<endl;
|
||||||
|
else
|
||||||
|
cout<<1<<endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Input: Enter string: aeiou??
|
||||||
|
Output: 0(bad string)
|
||||||
|
Time complexity: O(N)
|
|
@ -1,8 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
# Algorithms related to arrays
|
|
||||||
|
|
||||||
### C
|
|
||||||
|
|
||||||
1. [Unique Elements in an Array](c-or-cpp/unique-elements-in-an-array.c)
|
|
||||||
2. [Even and odd no. ](c-or-cpp/even-and-odd.c)
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Graphs
|
|
||||||
|
|
||||||
### C
|
|
||||||
|
|
||||||
1. [Prim's Algorithm](c-or-cpp/Prim's-algorithm.c)
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Linked Lists
|
|
||||||
|
|
||||||
### C
|
|
||||||
|
|
||||||
1. [Josephus Problem Using Circular Linked List](c-or-cpp/josephus-problem.c)
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Queues
|
|
||||||
|
|
||||||
### C
|
|
||||||
|
|
||||||
1. [Double Ended Queue (using arrays)](c-or-cpp/double-ended-queue-using-array.c)
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Sorting algorithms
|
|
||||||
|
|
||||||
### C
|
|
||||||
|
|
||||||
1. [Merge Sort](c-or-cpp/merge-sort.c)
|
|
|
@ -1,7 +0,0 @@
|
||||||
# String Algorithms
|
|
||||||
|
|
||||||
### C or C++
|
|
||||||
|
|
||||||
1. [Palindrome Check](c-or-cpp/palindrome.c)
|
|
||||||
2. [Permutation of String](c-or-cpp/Permutation-of-String.c)
|
|
||||||
3. [Count Words](c-or-cpp/count-words.c)
|
|
Loading…
Reference in New Issue