语法周赛 Round 13 题解
2024年12月25日大约 2 分钟
TooY0ung 的数字游戏
- 子任务 1(30 分):由于
,题目中又保证了 ,所以 TooY0ung 的数字永远无法超过 TooSimple ,输出-1
即可。 - 子任务 2(30 分):保证了
,所以直接计算 即可。 - 子任务 3(40 分):满分做法除了无解情况,其实就是计算
,需要注意如果可以整除,答案要 ,不能整除向上取整就好。
#include<bits/stdc++.h>
using namespace std;
int x,y,a,b;
int main()
{
cin>>x>>y>>a>>b;
if(a<=b) puts("-1");
else
{
if((y-x)%(a-b)==0) cout<<(y-x)/(a-b)+1<<"\n";
else cout<<(y-x+a-b-1)/(a-b)<<"\n";
}
return 0;
}
TooY0ung 的美食之旅
- 子任务 1(30 分):由于输入的全部都是
,所以输出 就好了。 - 子任务 2(30 分):没有
的话只需要关注数字发生了几次改变即可。 - 子任务 3(40 分):其实只要在代码中统计有没有
出现,记录开心不开心即可,用一些变量存储以上各种情况,很容易实现代码。
#include<bits/stdc++.h>
using namespace std;
int n,x,no2,happy,unhappy,ans;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
if(x!=2&&no2==0)
{
no2=1;
if(x==1) unhappy=1;
else happy=1;
}
if(no2==1&&x==2) continue;
if(no2==1&&happy==1&&x==1&&unhappy==0)
{
happy=0,unhappy=1,ans++;
}
else if(no2==1&&unhappy==1&&x==3&&happy==0)
{
unhappy=0,happy=1,ans++;
}
}
cout<<ans<<"\n";
return 0;
}
TooY0ung 的 WrongAnswer
- 子任务 1(30 分):只有小写字母只要查找是否有小写的
wronganswer
就行了,这里可以直接用find
函数就行。 - 子任务 2(30 分):只有大写字母就需要找一下
WRONGANSWER
。 - 子任务 3(40 分):满分做法其实就是把字母全变大写或者小写,找 “
WRONGANSWER
” 和 “wronganswer
” 即可,在看同学们代码的时候,有一些不正确的写法被我的类似于 “WWRONGANSWER
” 数据卡掉了,同学们可以课下再改一下。
#include<bits/stdc++.h>
using namespace std;
string s;
string wa="wronganswer";
int main()
{
cin>>s;
int len=(int)s.size();
for(int i=0;i<len;i++)
{
if(s[i]>='A'&&s[i]<='Z') s[i]+='a'-'A';
}
if(s.find("wronganswer")!=s.npos) puts("Yes");
else puts("No");
return 0;
}
TooY0ung 的等差数列
正解就是输出 X 就行,因为题目中写了数列长度大于等于 1,所以可以长度为 1。
#include<bits/stdc++.h>
using namespace std;
int x;
int main()
{
cin >> x;
cout << 1 << '\n';
cout << x << '\n';
return 0;
}