题目大意:将字符串划分为CV与CVC的音节格式,中间由","分割 C(a,e) ,V(b,c,d)
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int c[N];//标记是否为C
char d[2 * N];//存储分割后要输出的字符
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
string s;
cin >> s;
int t = 0;
memset(c, 0, sizeof(c));//每次数组记得清空
memset(d, 0, sizeof(d));
for (int i = 0; i < n; i++)
{
if (s[i] == 'a' || s[i] == 'e')
{
c[i] = 1;
}
else
{
c[i] = 0;
}
}
for (int i = n - 1; i >= 0; i--)//倒叙来判断分割cv cvc,由于顺序遍历时c相同不好判断
{
if (c[i] == 1)//遇到是v的后面加"."
{
d[t++] = s[i--];//i--是在存储完这个数组后的数据后才i--运行的
d[t++] = s[i];
d[t++] = '.';
}
else
{
d[t++] = s[i--];
d[t++] = s[i--];
d[t++] = s[i];
d[t++] = '.';
}
}
for (int i = t - 2; i >= 0; i--)//记得最后第一个是".",要删去
{
cout << d[i];
}
cout << endl;
}
return 0;
}
E
题目大意:
偶数上的数相加等于奇数上的数相加,在一串数字的串中的l,r中找到此类情况,则输出YES,反之,输出NO;
#include <bits/stdc++.h>
using namespace std;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
long long s = 0;
map<long long, int> mp;
string ans = "NO";
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (i %2 ==0)
s += x;
else
s -= x;
mp[s]++;
if (mp[s] > 1 || s == 0)//s==0表示总和相等,s在mp出现的个数不止一次表示,说明有一段是重复后抵消完的
{
ans = "YES";
}
}
cout << ans << endl;
}
return 0;
}