题目链接
这次还是只做出来两道题,前两题都挺简单的,注意第二题需要开long long不开会wa,代码粘上来,以后可能会看吧
第一题
#include<iostream>
#include <string>
using namespace std;
string a, b;
int main()
{
char str1[110], str2[110];
cin >> str1 >> str2;
a += str1; b += str2;
if(a.length() != b.length())
{
cout << "NO";
return 0;
}
for(int i = 0, j = b.length() - 1; i < a.length(); i ++ ,j --)
{
if(a[i] != b[j])
{
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
第二题
#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
unordered_map<char, ll>mp;
ll ans;
char a[N];
int main()
{
cin >> a;
for(int i = 0; a[i]; ++i) mp[a[i]] ++;
for(auto x : mp)
{
ll k = x.second;
ans += k * k;
}
cout << ans << endl;
return 0;
}
第三题
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 1010, M = N * 10;
typedef long long ll;
char str[N];
int d[N], n;
bool inq[N];
int h[N], e[M], w[M], ne[M], idx;
void add(int a, int b, int c)
{
w[idx] = c; e[idx] = b; ne[idx] = h[a]; h[a] = idx ++;
}
void spfa()
{
queue<int>q;
memset(d, -0x3f, sizeof d);
d[0] = 0;q.push(0);inq[0] = 1;
while(q.size())
{
int t = q.front();q.pop();inq[t] = 0;
for(int i = h[t]; i != -1; i =ne[i])
{
int j = e[i];
if(d[j] < d[t] + w[i])
{
d[j] = d[t] + w[i];
if(!inq[j])
{
inq[j] = 1;
q.push(j);
}
}
}
}
}
int main()
{
memset(h, -1, sizeof h);
cin >> n >> (str + 1);
for(int i = 1; i <= n - 1; ++ i)
{
if(str[i] == '<') add(i, i + 1, 1);
else if(str[i] == '>') add(i + 1, i, 1);
else if(str[i] == '=') add(i, i + 1, 0), add(i + 1, i, 0);
}
for(int i = 1; i <= n; ++ i) add(0, i, 1);
spfa();
for(int i = 1; i <= n; ++ i) cout << d[i] << ' ';
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署