2023.3.12上机练习

1.201312-1原题网址
在这里插入图片描述
(我的80分代码)

#include<iostream>
#include<algorithm>
using namespace std;
int num[10000] = { 0 };
int main()
{
	int n;
	cin >> n;
	int count = 1;
	for (int i = 1; i <= n; i++)
		cin >> num[i];
	sort(num, num + n);
	int max = 0,c;
	for (int i = 2; i <= n; i++)
	{
		if (num[i] == num[i - 1])
		{
			count++;
			if (max < count)
			{
				max = count;
				c = num[i];
			}
		}
		else
			count = 1;
	}
	cout << c << endl;
	return 0;
}

(满分代码)

#include<iostream>
using namespace std;
int a[1000], b[1000];
int main()
{
    int n;
    cin >> n;
    int i;
    for (i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    int count = 0, j, max = 0, min = 0;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (a[i] == a[j])//记录该数出现次数
                count++;
        }
        if (max < count) {//找出出现次数最多的数
            max = count;
            min = a[i];
        }
        if (max == count && a[i] < min)
        {//出现次数相同的数,找出其中最小的数
            min = a[i];
        }
        count = 0;//记录完重置
    }
    printf("%d\n", min);
    return 0;
}

2.201312-2原题网址
在这里插入图片描述

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	getline(cin, a);
	int num = (a[0] - '0') * 1 + (a[2] - '0') * 2 + (a[3] - '0') * 3 + (a[4] - '0') * 4 + (a[6] - '0') * 5 + (a[7] - '0') * 6 + (a[8] - '0') * 7 + (a[9] - '0') * 8 + (a[10] - '0') * 9;
	num = num % 11;
	if (num == 10&&a[12]=='X')
	{
		printf("Right");
	}
	else if(num==10)
	{
		a[12] = 'X';
		for (int i = 0; i < 13; i++)
			cout << a[i];
	}
	else if (num == (a[12] - '0'))
		printf("Right");
	else
	{
		a[12] = num + '0';
		for (int i = 0; i < 13; i++)
			cout << a[i];
	}
	return 0;
}

3.201312-3原题网址
在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int max = 0;
	int num[1000] = { 0 };
	for (int i = 1; i <= n; i++)
	{
		cin >> num[i];
		if (num[i] > max)
			max = num[i];
	}

	for (int i = 1; i <= n; i++)
	{
		int min = num[i], count = 1;
		for (int j = i + 1; j <= n; j++)
		{
			count++;
			if (num[j] < min)
				min = num[j];
			if (count * min > max)
				max = count * min;
		}
	}
	cout << max;
	return 0;
}

4.201403-1原题网址
在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num[500] = { 0 };
	for (int i = 1; i <= n; i++)
		cin >> num[i];
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (num[i] + num[j] == 0)
				count++;
		}
	}
	cout << count << endl;
	return 0;
}

5.201409-1原题网址
在这里插入图片描述

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num[1000] = { 0 };
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num,num + n);
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (num[j] - num[i] == 1)
				count++;
		}
	}
	cout << count << endl;
	return 0;
}
  1. 201409-2原题网址
    在这里插入图片描述
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int n;
bool m[N][N];
int main()
{
    cin >> n;
    while (n--)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        for (int i = x1; i < x2; i++)
        {
            for (int j = y1; j < y2; j++)
            {
                m[i][j] = true;
            }
        }
    }
    int res = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            res += m[i][j];
        }
    }
    cout << res;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值