Clearance :
The problem is very interesting & not yet solved by many users when I am posting it's Solution & Clearance . After solving at 0.00 sec my Rank was 17 at that time. Problem Setted by Rujia Liu. Whatever, Let's go to the Problem Clearance .
- The problem says you to find out the Ratio between who Ended their chatting by Saying " hehe " or their Variance ( Variance = Different formation of Anything . Here Word. Like " hehehehehehehe" or "hehehehehehehehehehehehehehehehehehehehehehehehe" ) and The total number chat messages that indicates the end of Chat already .
- Any users of this Chat room can End chat with anything . you have to find the Distinct Ended chat message . And from that you have to find the Messages that has ended with the word "hehe" ( Or Variance ) .
- From this ratio you have to find out the Percentage of This Ratio's [ Round ] ( Not Floating point round ) Value.
Algorithm :
- As problem statement says you have to turn all the Character into Lowercase order and replace all the Non-alphabetic Character as Space ' '.
- At first you have to find the the number of Distinct Chat messages . You can do it by using MAP.
- From those list using MAP Iterator .... You have to find out the the Number of Messages that ends with "hehe" . Through "stringstream" You can separate all the word . And check whether it Contains "hehe" or Not ?
- Note that number of " he " in each word will be greater than 1 .
- Now find the Map Size and and count the "hehe" enders . Find out the ratio and Print it's percentage .
==============================================================================================
Code :
#include<bits/stdc++.h>
#define pii pair<string, string>
char parcent = '%';
using namespace std;
int main()
{
string inp, str, name1, name2;
map<pii, string>mymap;
map<pii, string>::iterator it;
map<string, bool>used;
mymap.clear();
used.clear();
while(getline(cin, inp) && inp.size()>0)
{
int sz = inp.size();
name1 ="", name2="", str="";
bool dashfound = false, colonfound = false;
for(int i=0; i<sz; )
{
if(inp[i]=='-' && inp[i+1]=='>') {dashfound = true; i=i+2; continue;}
if(inp[i]==':') {colonfound = true; i++; continue; }
if(!dashfound && !colonfound)
{
name1 = name1 + inp[i];
i++;
}
if(dashfound && !colonfound)
{
name2 = name2 + inp[i];
i++;
}
if(dashfound && colonfound)
{
if(isalpha(inp[i]))
{
inp[i] = tolower(inp[i]);
str = str + inp[i];
}
else
{
str = str + ' ';
}
i++;
}
}
//cout<<name1<<' '<<name2<<' '<<str<<endl;
if(used[name1])
{
mymap.erase(pii(name1, name2));
mymap.insert(make_pair(pii(name1, name2), str));
}
else if(used[name2])
{
mymap.erase(pii(name2, name1));
mymap.insert(make_pair(pii(name2, name1), str));
}
else
{
mymap.insert(make_pair(pii(name1, name2), str));
used[name1] = true;
}
}
string here;
int cnt = 0;
for(it = mymap.begin(); it!=mymap.end(); ++it)
{
here = it->second;
string s;
stringstream ss(here);
bool check = false;
while(ss>>s)
{
int sz = s.size();
int atcnt = 0;
if(sz>3)
{
for(int i=0; i<sz; )
{
if(s[i]=='h' && s[i+1]=='e')
{
i = i + 2; atcnt++;
}
else i++;
}
if(atcnt*2==sz) { check = true; break; }
}
}
if(check) cnt++;
}
int mapsize = mymap.size();
double point = ((cnt*1.0)/(mapsize*1.0))*100;
printf("%0.0lf%c\n", round(point), parcent);
return 0;
}
==============================================================================================
For Correctness Try This Input :
**** Click : http://pastebin.com/vEYhnsV5 ......
=>Question or Need Help ?? Leave a Comment .
No comments:
Post a Comment