I solve a problem1538E — Funny Substrings.
But I found a new test to hack myself. The hack test is :
input
`1
4
a := h
b := ahaabc
c = b + a
d = a + c`
output
1
But my code output 0. I want provide these test but I don't know how to provide my test.
My submissions id is 120211661. There is my code.
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<map>
#include<cstring>
#define int long long
using namespace std;
struct Node{
int val;
string pre,suf;
Node(string _s="")
{
val=0;
int len=min((int)_s.size(),3ll);
if(_s.size()!=0)pre=_s.substr(0ll,len);
if(_s.size()!=0)suf=_s.substr(max((int)_s.size()-3,0ll),len);
for(int i=0;i<=(int)(_s.size()-4ll);i++)
{
if(_s.substr(i,4)=="haha")
++val;
}
}
friend Node operator + (Node a,Node b)
{
Node ret=Node();
if(a.pre.size()<3||b.pre.size()<3)
{
ret=Node(a.suf+b.pre);
ret.val+=a.val+b.val;
}
else
{
ret.pre=a.pre;ret.suf=b.suf;
ret.val=a.val+b.val+Node(a.suf+b.pre).val;
}
return ret;
}
};
int t,n;
signed main()
{
// freopen("in.txt", "r", stdin);
cin>>t;
while(t--)
{
cin>>n;
map<string,Node>mp;
string last;
while(n--)
{
string x,opt;
cin>>x>>opt;
last=x;
if(opt==":=")
{
string s;
cin>>s;
mp[x]=Node(s);
}
else
{
string s1,s2;
cin>>s1>>s2>>s2;
mp[x]=mp[s1]+mp[s2];
}
}
cout<<mp[last].val<<'\n';
}
return 0;
}