-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from nivanjanapramod/master
Create MostFrequentWordInString.c
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
cout << "Value of inputs in your array?" << endl; | ||
int arraysize; | ||
cin >> arraysize; | ||
|
||
cout << "Input array elements:" << endl; | ||
|
||
string array[arraysize]; | ||
|
||
for(int i=0; i<arraysize; i++) | ||
{ | ||
cin >> array[i]; | ||
} | ||
|
||
int most_occur = 1; | ||
|
||
for(int i=0; i<arraysize-1; i++) | ||
{ | ||
int times_occur = 1; | ||
|
||
for(int j=i+1; j<arraysize; j++) | ||
{ | ||
if(array[i]==array[j]) | ||
times_occur = times_occur + 1; | ||
} | ||
|
||
if(times_occur>most_occur) | ||
{ | ||
most_occur = times_occur; | ||
} | ||
|
||
} | ||
|
||
if(most_occur>1) | ||
{ | ||
cout << "Most occuring: "; | ||
for(int i=0; i<arraysize-1; i++) | ||
{ | ||
int times_occur = 1; | ||
|
||
for(int j=i+1; j<arraysize; j++) | ||
{ | ||
if(array[i]==array[j]) | ||
times_occur = times_occur + 1; | ||
} | ||
|
||
if(times_occur==most_occur) | ||
{ | ||
cout << array[i] << " "; | ||
} | ||
} | ||
} | ||
|
||
else | ||
{ | ||
cout << "No specific array elements are repeating."; | ||
} | ||
|
||
return 0; |