2015 H 聊天止於呵呵

2021-07-17 03:31:31 字數 2506 閱讀 8584

問題描述

(現代版)俗話說:流言止於智者,聊天止於呵呵。輸入一段聊天記錄,你的任務是數一數有

多少段對話「止於呵呵」,即對話的最後一句話包含單詞 hehe 或者它的變形。

具體來說,我們首先提取出對話的最後一句話,把所有非字母的字元替換成空格,把所有字元 替換成小寫,然後匯出乙個單詞列表(由空格隔開),只要列表中的任何乙個單詞是 hehe,這 段對話就算作「止於呵呵」。比如,"hi! are you ok?" 會變成四個單詞:hi, are, you, ok。注 意,單詞列表可以是空的(比如,這句話是:"?!?!!")

有些人喜歡使用 hehe 的變形,這些變形也應被視為「呵呵」。為了簡單起見,本題只考慮由 n(n>1)個 he 連線而成的單詞,比如 hehehe 或者 hehehehe。注意,以 hehe 為連續子串的其他單 詞不應視為「呵呵」,比如 hehee,或者 ehehe。

每兩個不同人之間的所有對話算作「一段對話」。 輸入

輸入僅包含一組資料,每行是一句對話,格式為: 

人名1->人名2: 一句話.

每行最多包含 1000 個字元,最多 100 行。 輸出

輸出「止於呵呵」的對話段落所佔的百分比,四捨五入到最近的整數。輸入資料保證答案不會同時和兩個整數最近。

樣例輸入

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.

樣例輸出

50%
題目描述:判斷每段對話的最後一句是否含有he或者hehehe(n個he)這種單詞,求得有這種特性的對話佔總對話的比
例。
解題思路:此題屬於簡單模擬題,這裡各種處理很適合stl的發揮,可以用map來儲存對話人物和對話內容,將map
的key設定成set,這樣就保證了輸入完成時,

map儲存的是每段對話的最後一句話,set由於能進行自動排序,直接

將兩個人的名字放進去,然後map的value就儲存談話內容,這樣就有效的分割出要

處理的串了,在判斷hehe特性

時,可以利用stringstream這個子串輸入輸出流來分解談話內容,用函式判斷單詞是不是hehe特性。
stl真強大,佩服!
該字元,

但是最後的字元不會處理scanf("%[^\n]\n",str);但是最後的\n字元處理不了,所以在迴圈中就用getchar()

由於沒有oj提交此**,如若發現錯誤,acmer直接指出,弱弱會修改。

抱歉之前的**有個小bug,題意沒審清楚,改了,a了。
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;

typedef __int64 ll;

const double pi = acos(-1);

const double eps = 1e-8;

const int inf = 0x3f3f3f3f;

const int maxm = 1000000;

const int maxn = 20000+10;

const int mod = 1000000007;

templateinline t minn(t a,t b,t c)

templateinline t maxx(t a,t b,t c)

#define clr(a,b) memset((a),(b),sizeof(a))

char str1[maxn];

char str2[maxn];

char str3[maxn];

int cnt=0;

int sum=0;

map,string> ma;

bool jdhehe(string s)

return true;

}int main()

string s;

stringstream in;

sum = ma.size();

map,string>::iterator it = ma.begin();

for(;it!=ma.end();++ it)

}if(flag)

cnt++;

} double ans = (1.0*cnt/sum)*100;

printf("%.0lf%%", ans);

}