problem link-click here
it's an easy implement based string processing problem. just read the question statement carefully.
an accepted code is given below:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
bool arr[150]={0};
vector<int> v;
vector<char> v1;
for(int i=0;i<str.length();i++)
{
int c=0;
if(arr[str[i]]==0 && ((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122)) )
{
for(int j=i;j<str.length();j++)
{
if(str[i]==str[j])
{
c++;
}
}
arr[str[i]]=1;
v.push_back(c);
v1.push_back(str[i]);
}
}
for(int i=0;i<v.size()-1;i++)
{
for(int j=i+1;j<v.size();j++)
{
if(v[i]>v[j])
{
int temp=v[i];
v[i]=v[j];
v[j]=temp;
char temp1=v1[i];
v1[i]=v1[j];
v1[j]=temp1;
}
}
}
bool arr1[150]={0};
vector<char> v2;
arr1[v[v.size()-1]]=1;
for(int i=0;i<v.size();i++)
{
if(arr1[v[i]]==1)
{
v2.push_back(v1[i]);
}
}
sort(v2.begin(),v2.end());
for(int i=0;i<v2.size();i++)
{
cout<<v2[i];
}
cout<<" "<<v[v.size()-1]<<endl;
}
return 0;
}
it's an easy implement based string processing problem. just read the question statement carefully.
an accepted code is given below:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
bool arr[150]={0};
vector<int> v;
vector<char> v1;
for(int i=0;i<str.length();i++)
{
int c=0;
if(arr[str[i]]==0 && ((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122)) )
{
for(int j=i;j<str.length();j++)
{
if(str[i]==str[j])
{
c++;
}
}
arr[str[i]]=1;
v.push_back(c);
v1.push_back(str[i]);
}
}
for(int i=0;i<v.size()-1;i++)
{
for(int j=i+1;j<v.size();j++)
{
if(v[i]>v[j])
{
int temp=v[i];
v[i]=v[j];
v[j]=temp;
char temp1=v1[i];
v1[i]=v1[j];
v1[j]=temp1;
}
}
}
bool arr1[150]={0};
vector<char> v2;
arr1[v[v.size()-1]]=1;
for(int i=0;i<v.size();i++)
{
if(arr1[v[i]]==1)
{
v2.push_back(v1[i]);
}
}
sort(v2.begin(),v2.end());
for(int i=0;i<v2.size();i++)
{
cout<<v2[i];
}
cout<<" "<<v[v.size()-1]<<endl;
}
return 0;
}
No comments:
Post a Comment