题目:
现代版)俗话说:流言止于智者,聊天止于呵呵。输入一段聊天记录,你的任务是数一数有

多少段对话“止于呵呵”,即对话的最后一句话包含单词 hehe 或者它的变形。

具体来说,我们首先提取出对话的最后一句话,把所有非字母的字符替换成空格,把所有字符 替换成小写,然后导出一个单词列表(由空格隔开),只要列表中的任何一个单词是 hehe,这 段对话就算作“止于呵呵”。比如,”Hi! Are you OK?” 会变成四个单词:hi, are, you, ok。注 意,单词列表可以是空的(比如,这句话是:”?!?!!”)

有些人喜欢使用 hehe 的变形,这些变形也应被视为“呵呵”。为了简单起见,本题只考虑由 n(n>1)个 he 连接而成的单词,比如 hehehe 或者 hehehehe。注意,以 hehe 为连续子串的其他单 词不应视为“呵呵”,比如 hehee,或者 ehehe。

每两个不同人之间的所有对话算作“一段对话”。

Input
输入仅包含一组数据,每行是一句对话,格式为:
人名1->人名2: 一句话.
每行最多包含 1000 个字符,最多 100 行。
Output
输出“止于呵呵”的对话段落所占的百分比,四舍五入到最近的整数。输入数据保证答案不会
同时和两个整数最近。
Sample Input

A->B: Hello!
A->C: Hi!
B->A: Hehe
B->D: Hei!
D->B: How are you?
A->C: Hi???
A->C: Are you there?
B->D: Hehehei!
D->B: What does hehehei mean?
F->E: I want to hehehehehe yah.

Sample Output

50%

Hint

样例解释
A 和 B 之间的最后一句话是”Hehe”.
A 和 C 之间的最后一句话是”Are you there?”.
B 和 D 之间的最后一句话是”What does hehehei mean?”.
E 和 F 之间的最后一句话是”I want to hehehehehe yah”. 最后第一段和最后一段话是“止于呵呵”的(注意最后一段对话是以呵呵的变种结束),因此 比例是 50%。

题目:这个题就是字符串的模拟的一个题目,习惯性用string,这个题在整行读入的时候忘记string不能读入空格,犯了这么低级的错误,浪费了很多时间

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#define cl(a) memset(a,0,sizeof(a))
using namespace std;
char a[1005];
map<string,int>mp;
int s[205][205];
bool check(string k)
{
    if(k.size()==0)return false;
    for(int i=0;i<k.size();i++)
    {
        if(k[0]!='h') return false;
        else
        {
            if(k[i]=='h'&&k[i+1]=='e')
            {
                i++;
            }
            else
            {
                return false;
            }
        }
    }
    return true;
}
bool change(char k[],int st,int ed)
{
    string m;
    int flag=0;
    for(int i=st; i<ed; i++)
    {
        if(k[i]>='A'&&k[i]<'Z')
        {
            k[i]+='a'-'A';
            m+=k[i];
        }
        else if(k[i]>='a'&&k[i]<='z')
        {
            m+=k[i];
            continue;
        }
        else
        {
            if(check(m))flag=1;
            //else flag=0;
            m.clear();
        }
    }
    if(check(m))flag=1;
    if(flag)return true;
    else return false;
}
int main()
{
    int cnt=0;
    cl(s);
    while(gets(a))
    {

        int len=strlen(a);
        int st=0;
        string name1,name2;
        for(int i=0; i<len; i++)
        {
            if(a[i]=='-'&&a[i+1]=='>')
            {
                st=i+2;
                break;
            }
            name1+=a[i];
        }
        if(!mp.count(name1))
            mp[name1]=++cnt;
        int st2=0;
        for(int i=st; i<len; i++)
        {
            if(a[i]==':')
            {
                st2=i+1;
                break;
            }
            name2+=a[i];
        }
        if(!mp.count(name2))
        {
            mp[name2]=++cnt;
        }
        int u=mp[name1];
        int v=mp[name2];
        //cout<<name1<<" "<<name2<<endl;
        //cout<<u<<" "<<v<<endl;
        if(change(a,st2,len))
        {
            s[u][v]=s[v][u]=1;
        }
        else
        {
            s[u][v]=s[v][u]=-1;
        }
        //cout<<s[u][v]<<endl;
    }
    int all=0,right=0;
    for(int i=0;i<201;i++)
    {
        for(int j=i;j<201;j++)
        {
            if(s[i][j]==0)continue;
            else
            {
                all++;
                if(s[i][j]==1)right++;
            }
        }
    }
    //cout<<all<<endl;
    //cout<<right<<endl;
    double percent=100*(right/(all*1.0));
    printf("%.0lf%%\n",percent);
    return 0;
}