# 11.25lc每日一题-809. 情感丰富的文字()-其他

## 11.25lc每日一题-809. 情感丰富的文字()

1 <= s.length, words.length <= 1001 <= words[i].length <= 100s 和所有在 words 中的单词都只由小写字母组成。

``````class Solution {
int book[105] = {0};
struct node
{
char x;
int use = 1;//若果字符顺序不匹配直接弃用
int times = 0;//连续相同字符的长度
}e[105][105];
int ans=0;
public:
int expressiveWords(string s, vector<string>& words) {
char pre = s[0];
int temp = 1;
for(int i = 0;i<s.length();i++)//记录下s的字符分布情况
{
if(s[i]==pre)
{
e[100][temp].x = s[i];
e[100][temp].times+=1;
pre = s[i];
}
else
{
temp++;
e[100][temp].x = s[i];
e[100][temp].times++;
pre = s[i];
}
}
int k = temp;
//cout<<k<<endl;
for(int i = 0;i<words.size();i++)//对每一个words也记录下分布
{
pre = words[i][0];
temp = 1;
for(int j=0;j<words[i].length();j++)
{
if(words[i][j]==pre)
{
e[i][temp].x = words[i][j];
e[i][temp].times+=1;
pre = words[i][j];
}
else
{
temp++;
e[i][temp].x = words[i][j];
e[i][temp].times++;
pre = words[i][j];
}
}
if(temp!=k)//如果分布情况不一样直接弃用
{
book[i] = 1;
}
}
for(int i = 0;i<words.size();i++)
{
int flag = 0;
for(int j = 1;j<=k;j++)
{
if(book[i]==1)
{
flag = 0;
break;
}
if(e[i][j].x!=e[100][j].x)//单词出现的顺序不一样
{
flag = 0;
break;
}
else{
if(e[i][j].times>e[100][j].times)//已经大于,不存在扩张
{
flag = 0;
break;
}
else{
if(e[100][j].times==e[i][j].times)
{
flag++;
}
else if(e[100][j].times-e[i][j].times>=0&&e[100][j].times>=3)
{

flag++;
}
}
}
}
if(flag==k)//得到相同分布,ans++
{
ans++;
}
}
return ans;
}
};``````
————————

1 <= s.length, words.length <= 1001 <= words[i].length <= 100s 和所有在 words 中的单词都只由小写字母组成。

``````class Solution {
int book[105] = {0};
struct node
{
char x;
int use = 1;//若果字符顺序不匹配直接弃用
int times = 0;//连续相同字符的长度
}e[105][105];
int ans=0;
public:
int expressiveWords(string s, vector<string>& words) {
char pre = s[0];
int temp = 1;
for(int i = 0;i<s.length();i++)//记录下s的字符分布情况
{
if(s[i]==pre)
{
e[100][temp].x = s[i];
e[100][temp].times+=1;
pre = s[i];
}
else
{
temp++;
e[100][temp].x = s[i];
e[100][temp].times++;
pre = s[i];
}
}
int k = temp;
//cout<<k<<endl;
for(int i = 0;i<words.size();i++)//对每一个words也记录下分布
{
pre = words[i][0];
temp = 1;
for(int j=0;j<words[i].length();j++)
{
if(words[i][j]==pre)
{
e[i][temp].x = words[i][j];
e[i][temp].times+=1;
pre = words[i][j];
}
else
{
temp++;
e[i][temp].x = words[i][j];
e[i][temp].times++;
pre = words[i][j];
}
}
if(temp!=k)//如果分布情况不一样直接弃用
{
book[i] = 1;
}
}
for(int i = 0;i<words.size();i++)
{
int flag = 0;
for(int j = 1;j<=k;j++)
{
if(book[i]==1)
{
flag = 0;
break;
}
if(e[i][j].x!=e[100][j].x)//单词出现的顺序不一样
{
flag = 0;
break;
}
else{
if(e[i][j].times>e[100][j].times)//已经大于,不存在扩张
{
flag = 0;
break;
}
else{
if(e[100][j].times==e[i][j].times)
{
flag++;
}
else if(e[100][j].times-e[i][j].times>=0&&e[100][j].times>=3)
{

flag++;
}
}
}
}
if(flag==k)//得到相同分布,ans++
{
ans++;
}
}
return ans;
}
};``````