
目录
1. 成绩打印 ※
2. 按要求补齐数组 🌟🌟🌟
3. 水仙花数 ※
🌟 每日一练刷题专栏 🌟
Golang每日一练 专栏
Python每日一练 专栏
C/C++每日一练 专栏
Java每日一练 专栏
1. 成绩打印
一个班有10个同学,通过键盘输入成绩, 并打印输出,每行输出5个同学的成绩。并求出平均成绩,最高分、最低分并输出。算法分析:
 (1)定义一个数组用来存放10个成绩数据。
 (2)用循环结构实现成绩输入;
 (3)用循环结构实现成绩输出,并控制换行;
 (4)使用循环结构求平均成绩、最高分、最低分并输出。
以下程序实现了这一功能,请你填补空白处内容:
```c++
 #include <stdio.h>
 int main(){
     int x,i,max=0,min=0;
     double sum=0,ave=0;
     int a[10];
     for(i=0;i<10;i++){
         scanf("%d",&a[i]);
         if(i==0)
             min = a[i];
         sum+=a[i];
         ____________;
     }
     ave=sum/10;
     for(i=0;i<5;i++)
         printf("%d ",a[i]);
      printf("\n");
     for(i=5;i<10;i++)
         printf("%d ",a[i]);
     printf("平均成绩%f,最高分%d,最低分%d ",ave,max,min);
 }
 ```
出处:
https://edu.csdn.net/practice/27637459
代码:
#include <stdio.h>
int main(){
    int x,i,max=0,min=0;
    double sum=0,ave=0;
    int a[10];
    for(i=0;i<10;i++){
        scanf("%d",&a[i]);
        if(i==0)
            min = a[i];
        sum+=a[i];
        if(max<a[i])
            max=a[i];
        if(min>a[i])
            min=a[i];
    }
    ave=sum/10;
    for(i=0;i<5;i++)
        printf("%d ",a[i]);
     printf("\n");
    for(i=5;i<10;i++)
        printf("%d ",a[i]);
    printf("平均成绩%f,最高分%d,最低分%d ",ave,max,min);
}输出:
略
2. 按要求补齐数组
给定一个已排序的正整数数组 nums,和一个正整数 n 。从 [1, n] 区间内选取任意个数字补充到 nums 中,使得 [1, n] 区间内的任何数字都可以用 nums 中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。
示例 1:
输入: nums = [1,3], n = 6 输出: 1 解释: 根据 nums 里现有的组合 [1], [3], [1,3],可以得出 1, 3, 4。 现在如果我们将 2 添加到 nums 中, 组合变为: [1], [2], [3], [1,3], [2,3], [1,2,3]。 其和可以表示数字 1, 2, 3, 4, 5, 6,能够覆盖 [1, 6] 区间里所有的数。 所以我们最少需要添加一个数字。
示例 2:
输入: nums = [1,5,10], n = 20 输出: 2 解释: 我们需要添加 [2, 4]。
示例 3:
输入: nums = [1,2,2], n = 5 输出: 0
出处:
https://edu.csdn.net/practice/27637460
代码:
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int minPatches(vector<int> &nums, int n)
    {
        long max_sum = 0;
        int m = nums.size();
        int cnt = 0;
        for (long i = 1, pos = 0; i <= n;)
        {
            if (pos >= m || i < nums[pos])
            {
                cnt++;
                max_sum += i;
            }
            else
            {
                max_sum += nums[pos];
                pos++;
            }
            i = max_sum + 1;
        }
        return cnt;
    }
};
int main()
{
	Solution s;
	vector<int> nums = {1, 3};
	cout << s.minPatches(nums, 6) << endl;
	nums = {1, 5, 10};
	cout << s.minPatches(nums, 20) << endl;
	nums = {1, 2, 2};
	cout << s.minPatches(nums, 5) << endl;
	return 0;
}输出:
1
 2
 0
3. 水仙花数
检查一个3位数是否是水仙花数。
输入:一个数字,比如 371,输出:x是水仙花数,
如果不是,则输出:x不是水仙花数。
注:x为输入的数字
以下程序实现了这一功能,请你补全空白处内容:
```c++
 #include <iostream>
 using namespace std;
 int main()
 {
     int a, b, c, y, n = 0;
     cout << "请输入三位数字:" << endl;
     cin >> n;
     a = n % 1000 / 100;
     b = n % 100 / 10;
     c = n % 10 / 1;
     ___________________;
     if (y == n)
         cout << n << "是水仙花数" << endl;
     else
         cout << n << "不是水仙花数" << endl;
     return 0;
 }
 ```
出处:
https://edu.csdn.net/practice/27637461
代码:
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, y, n = 0;
    cout << "请输入三位数字:" << endl;
    cin >> n;
    a = n % 1000 / 100;
    b = n % 100 / 10;
    c = n % 10 / 1;
    y = a * a * a + b * b * b + c * c * c;
    if (y == n)
        cout << n << "是水仙花数" << endl;
    else
        cout << n << "不是水仙花数" << endl;
    return 0;
}输出:
略
🌟 每日一练刷题专栏 🌟
✨ 持续,努力奋斗做强刷题搬运工!
👍 点赞,你的认可是我坚持的动力!
🌟 收藏,你的青睐是我努力的方向!
✎ 评论,你的意见是我进步的财富!
☸ 主页:https://hannyang.blog.csdn.net/
|  | Golang每日一练 专栏 | 
|  | Python每日一练 专栏 | 
|  | C/C++每日一练 专栏 | 
|  | Java每日一练 专栏 | 



















