成都X02 第一次小测 题解汇总
2023-08-12 18:34:19
发布于:江苏
第一题:动物农场
概念:程序基本语句:输入输出
代码如下:
#include<iostream>
using namespace std;
int main(){
    cout<<"All animals are equal, but some animals are more equal than others.";
}
第二题:加法问题
概念:程序基本语句:输入输出 + 分支语句
代码如下:(代码里用了函数)
#include<bits/stdc++.h>
using namespace std;
int r(string k){
    if(k=="零") return 0;
    if(k=="壹") return 1;
    if(k=="贰") return 2;
    if(k=="叁") return 3;
    if(k=="肆") return 4;
    if(k=="伍") return 5;
    if(k=="陆") return 6;
    if(k=="柒") return 7;
    if(k=="捌") return 8;
    if(k=="玖") return 9;
    if(k=="拾") return 10;
}
int add(string a,string b){
    return r(a)+r(b);
}
int main(){
    string a,b;
    cin>>a>>b;
    cout<<add(a,b);
    return 0;
}
第三题:一无所知的IKUN
概念:程序基本语句:输入输出
代码如下:
#include<iostream>
using namespace std;
int main(){
	char k[1001];
	cin>>k;
	cout<<"我不知道什么是"<<k<<",请不要打扰我!\n";
	return 0;
}
第四题:拼数游戏
概念:程序基本语句: 特殊判定 + 输入输出
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef string ll;
int main(){
    ll a,b;
    cin>>a>>b;
    if(a=="0" and b=="0"){
        cout<<"0";
        return 0;
    }
    if(a>b) cout<<a+b;
    else if(a==b) cout<<a+a;
    else cout<<b+a;
    return 0;
}
第五题:电灯开关游戏
概念:程序基本语句: 一维数组 + 分支语句
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int cnt[5054];
    for(int i=1;i<=n;i++){
        cnt[i]=1;
    }
    for(int i=1;i<=m;i++){
		int k;
        cin>>k;
        if(cnt[k]==0) cnt[k]=1;
        else if(cnt[k]==1) cnt[k]=0;
        if(cnt[k+1]) cnt[k+1]=0;
        else cnt[k+1]=1;
        if(cnt[k-1]) cnt[k-1]=0;
        else cnt[k-1]=1;
    }
    int sum=0;
    for(int i=1;i<=n;i++){
		if(cnt[i]) sum++;
    }
    cout<<sum;
    return 0;
}
第六题:车厢重组(LUOGU原题改编)
概念:程序基本语句: 循环语句 + 输入输出
代码如下:
#include <iostream>
using namespace std;
int n, sum;
int main()
{
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j)
            if (a[j] > a[i])
                ++sum;
    cout << sum;
    return 0;
}
全部评论 3
太厉害了 肖老师
2023-08-12 来自
0???????
2023-08-12 来自 江苏
0
我不是老师
2023-08-12 来自 江苏
0都是正确的代码,大家今天测试要加油呀
2023-08-12 来自 江苏
0









有帮助,赞一个