比赛链接:bUNIQUE VISION Programming Contest 2024 Autumn (AtCoder Beginner Contest 373) - AtCoder
A-September
思路:读入每一个字符,判断字符串长度和当前字符串的次序是否一致。
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
string str[15];
int cnt=0;
int main()
{
rep(i,1,12)
{
cin >> str[i];
if(str[i].size()==i)
{
cnt++;
}
}
cout << cnt;
return 0;
}
B-1D Keyboard
思路:枚举当前要按的字母,每次遍历键盘,计算当前要按的字母和上一个按的字母的距离,累加一下。
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int pos[30];
char wd[30];
int dis=0;
int main()
{
rep(i,0,25)
{
cin >> wd[i];
pos[wd[i]-'A']=i;
}
rep(i,0,25)
{
if(i>0)
{
dis+=abs(pos[i]-pos[i-1]);
}
}
cout << dis;
return 0;
}
C-Max Ai+Bj
思路:遍历两个数组,找到两个数组中最大的元素,相加直接输出。
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define LL long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
LL N,n1[500050],n2[500050],maxn1=-1000000000,maxn2=-1000000000;
int main()
{
cin >> N;
rep(i,1,N)
{
cin >> n1[i];
if(n1[i]>maxn1)
{
maxn1=n1[i];
}
}
rep(i,1,N)
{
cin >> n2[i];
if(n2[i]>maxn2)
{
maxn2=n2[i];
}
}
cout << maxn1+maxn2;
return 0;
}
690

被折叠的 条评论
为什么被折叠?



