Finding the frequency of each characters
BTech CSE student at IIIT Ranchi | Aspiring Software Engineer | Passionate about coding, building innovative projects, and solving real-world problems through technology. Currently diving into web development, Machine learning and deep learning. Always learning, creating, and pushing boundaries! #Tech #Coding
#Finding frequency of each character in an string without using the hash-map…
// printing the frequency of each character..without using hashmap..
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s);
vector<int> v(26,0);//frequency array..special array..
for(int i=0;i<s.length();i++){
char ch = s[i];
int x = (int)ch;
int idx = x-97;
v[idx]+=1;
}
for(int i=0;i<v.size();i++){
if(v[i]!=0){
int ascii = 97+i;
cout<<(char)ascii<<" "<<v[i]<<endl;
}
}
return 0;
}
You can also do it easily using a char and integer map .. bye bye ..
