这里写目录标题
https://codeforces.com/contest/1997
A模拟题【AC】
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
void solve()
{
string a;cin>>a;
if(a.length()==1)
{
if(a[0]=='z')a.insert(0,1,'a');
else a.insert(0,1,a[0]+1);
cout<<a<<endl;
return ;
}
int f2=0;
int n=a.length();
for(int i=0;i<n-1;i++)
{
if(a[i]==a[i+1])
{
f2=1;
if(a[i]=='z')a.insert(i+1,1,'a');
else a.insert(i+1,1,a[i]+1);
break;
}
}
if(f2==0)
{
if(a[n-1]=='z')a.insert(n,1,'a');
else a.insert(n,1,a[n-1]+1);
}
cout<<a<<endl;
return ;
}
int main()
{
int t;cin>>t;
while(t--)
{
solve();
}
return 0;
}
B【补题】
C贪心、栈、括号匹配【AC】
#include <iostream>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;
void solve()
{
int n,res=0;cin>>n;
string s;cin>>s;
stack<pair<int,char>> st;
st.push({0,'_'});
for(int i=1;i<s.length();i++)
{
if(s[i]=='_')
{
if(!st.empty()&&st.top().second=='(')// '_'匹配'(',
{
res = res + i - st.top().first;
st.pop();
}
else st.push({i,'_'});
}
else if(s[i]=='(')
{
st.push({i,'('});
}
else if(s[i]==')')// ')'匹配'_'
{
if(!st.empty()&&st.top().second=='_')
{
res = res + i - st.top().first;
st.pop();
}
}
}
cout<<res<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
{
solve();
}
return 0;
}