From 315f925d02499c9cf7a1eaf6cd7ca7c0bbb1f621 Mon Sep 17 00:00:00 2001 From: Yaseen Abbas Date: Thu, 31 Oct 2019 22:53:31 +0530 Subject: [PATCH] Program Added To Count String Occurence --- CPP/Algorithm/Count_Occurence.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CPP/Algorithm/Count_Occurence.c diff --git a/CPP/Algorithm/Count_Occurence.c b/CPP/Algorithm/Count_Occurence.c new file mode 100644 index 0000000..e635dbc --- /dev/null +++ b/CPP/Algorithm/Count_Occurence.c @@ -0,0 +1,26 @@ +/*input +*/ + +#include +#define ll long long int +#define nl cout<<"\n" +using namespace std; + + +int main() +{ + // only for lower case alphabet + string s = "aaabbcc"; + int occur[26] = {0}; + for (int i = 0; i < s.length(); i++) { + occur[s[i] - 'a']++; + } + char c = 'a'; + for (int i = 0; i < 26; i++) { + cout << c << " occurs " << occur[i] << " times\n"; + c++; + } + return 0; +} + +