题解:P14317 「ALFR Round 11」A 浴眼盯真 (dingzhen)
简单题,建议下位橙。
对于第一个条件,只需开一个大小为
int cnt[26];
for (int i = 0; i < n; i++)
{
cnt[s[i] - 'a']++;
}
对于第二个条件,设输入的字符串为
if (cnt[s[0] - 'a'] > 1 || cnt[s[n - 1] - 'a'] > 1) cout << "Yes\n"; // 只要有其中一个子串满足条件即可
else cout << "No\n2\n";
:::success[完整代码]
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s;
int cnt[26];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--)
{
bool f = 1;
cin >> s;
int n = s.size();
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
for (int i = 0; i < 26; i++)
{
if (cnt[i] == 0)
{
f = 0;
break;
}
}
if (!f)
{
cout << "No\n1 2\n";
continue;
}
if (cnt[s[0] - 'a'] > 1 || cnt[s[n - 1] - 'a'] > 1) cout << "Yes\n";
else cout << "No\n2\n";
}
return 0;
}
:::