提交 f17722dd 编写于 作者: 每日一练社区's avatar 每日一练社区

update dailycode pipline data

上级 863ca5e4
......@@ -3,6 +3,42 @@
<p>给定公司N名员工的工龄&#xff0c;要求按工龄增序输出每个工龄段有多少员工。输入首先给出正整数N&#xff0c;即员工总人数&#xff1b;
随后给出N个整数&#xff0c;即每个员工的工龄&#xff0c;范围在[0, 99]。其中&#xff0c;0-9为第1个工龄段&#xff0c;10-19为第2个工龄段&#xff0c;&#xff0c;90-99为第10个工龄段。按工龄的递增顺序输出每个工龄的员工个数&#xff0c;格式为&#xff1a;“工龄:人数”。每项占一行。如果人数为0则不输出该项。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
int main()
{
int i,n,a[11]= {0},x;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&x);
if(x<=9)
a[1]++;
else if(x>9&&x<=19)
a[2]++;
else if(x>19&&x<=29)
a[3]++;
else if(x>29&&x<=39)
a[4]++;
else if(x>39&&x<=49)
a[5]++;
else if(x>49&&x<=59)
a[6]++;
else if(x>59&&x<=69)
a[7]++;
else if(x>69&&x<=79)
a[8]++;
else if(x>79&&x<=89)
a[9]++;
else
a[10]++;
}
________________
}
```
## template
```cpp
......@@ -46,7 +82,11 @@ int main()
## 答案
```cpp
for(i=1;i<=10;i++){
if(a[i]>0){
printf("%d-%d:%d\n",i*10-10,i*10-1,a[i]);
}
}
```
## 选项
......@@ -54,17 +94,29 @@ int main()
### A
```cpp
for(i=0;i<=10;i++){
if(a[i]>0){
printf("%d-%d:%d\n",i*10-10,i*10-1,a[i]);
}
}
```
### B
```cpp
for(i=1;i<=10;i++){
if(a[i]>0){
printf("%d-%d:%d\n",i*10,i-1,a[i]);
}
}
```
### C
```cpp
for(i=0;i<=10;i++){
if(a[i]>0){
printf("%d-%d:%d\n",i*10,i-1,a[i]);
}
}
```
\ No newline at end of file
......@@ -2,40 +2,86 @@
有一分数序列:2/1,-3/2,5/3,-8/5,13/8,-21/13,…, 由用户输入项目数N,求这个数列的前N 项之和
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdlib.h>
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int i;
double a1 = 2, b1 = 1;
double a2 = 3, b2 = 2;
double sum = a1 / b1 - a2 / b2;
if (n == 1)
printf("%f\n", a1 / b1);
else if (n == 2)
printf("%f\n", sum);
else
{
for (i = 0; i < n - 2; i++)
{
double exp = a2 / b2;
_____________________
sum += exp;
double a = a1 + a2;
double b = b1 + b2;
a1 = a2;
b1 = b2;
a2 = a;
b2 = b;
}
printf("%f\n", sum);
}
return 0;
}
```
## template
```cpp
#include<stdlib.h>
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int i;
double a1 = 2, b1 = 1;
double a2 = 3, b2 = 2;
double sum = a1/b1 - a2/b2;
if(n==1) printf("%f\n",a1/b1);
else if (n==2) printf("%f\n",sum);
else{
for(i = 0;i<n-2;i++){
double exp = a2 / b2;
if(i%2==0) exp *= -1;
sum += exp;
double a = a1 + a2;
double b = b1 + b2;
a1 = a2;b1 = b2;
a2 = a; b2 = b;
}
printf("%f\n",sum);
}
return 0;
#include <stdlib.h>
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int i;
double a1 = 2, b1 = 1;
double a2 = 3, b2 = 2;
double sum = a1 / b1 - a2 / b2;
if (n == 1)
printf("%f\n", a1 / b1);
else if (n == 2)
printf("%f\n", sum);
else
{
for (i = 0; i < n - 2; i++)
{
double exp = a2 / b2;
if (i % 2 == 0)
exp *= -1;
sum += exp;
double a = a1 + a2;
double b = b1 + b2;
a1 = a2;
b1 = b2;
a2 = a;
b2 = b;
}
printf("%f\n", sum);
}
return 0;
}
```
## 答案
```cpp
if (i % 2 == 0)
exp *= -1;
```
## 选项
......@@ -43,17 +89,20 @@ int main(){
### A
```cpp
if (i % 2 == 0)
exp = -1;
```
### B
```cpp
if (i / 2 == 0)
exp *= -1;
```
### C
```cpp
if (i / 2 == 0)
exp = -1;
```
\ No newline at end of file
# 输入一个正整数n(代表图形的行数),输出如样例形式的图形。
输入:7
输出:
D D
CD DC
BCD DCB
ABCDDCBA
BCD DCB
CD DC
D D
```json
D D
CD DC
BCD DCB
ABCDDCBA
BCD DCB
CD DC
D D
```
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<string> a(n, ""), b(n, "");
int m = (n + 1) / 2;
int p = 0;
for (int i = m - 1; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
a[i].push_back('A' + j + p);
b[i] = a[i];
reverse(b[i].begin(), b[i].end());
___________________
p++;
}
p = 0;
for (int i = n - 1; i >= m; i--)
{
a[i] = a[p];
b[i] = b[p++];
}
for (int i = 0; i < n; i++)
cout << a[i] << b[i] << endl;
return 0;
}
```
## template
```cpp
#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin>>n;
vector<string> a(n,""),b(n,"");
int m=(n+1)/2;
int p=0;
for(int i=m-1;i>=0;i--){
for(int j=0;j<=i;j++)
a[i].push_back('A'+j+p);
b[i]=a[i];
reverse(b[i].begin(),b[i].end());
for(int j=i+1;j<m;j++){
a[i]+=" ";
b[i]+=" ";
}
p++;
}
p=0;
for(int i=n-1;i>=m;i--){
a[i]=a[p];
b[i]=b[p++];
}
for(int i=0;i<n;i++)
cout<<a[i]<<b[i]<<endl;
return 0;
int main()
{
int n;
cin >> n;
vector<string> a(n, ""), b(n, "");
int m = (n + 1) / 2;
int p = 0;
for (int i = m - 1; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
a[i].push_back('A' + j + p);
b[i] = a[i];
reverse(b[i].begin(), b[i].end());
for (int j = i + 1; j < m; j++)
{
a[i] += " ";
b[i] = " " + b[i];
}
p++;
}
p = 0;
for (int i = n - 1; i >= m; i--)
{
a[i] = a[p];
b[i] = b[p++];
}
for (int i = 0; i < n; i++)
cout << a[i] << b[i] << endl;
return 0;
}
```
## 答案
```cpp
for (int j = i + 1; j < m; j++)
{
a[i] += " ";
b[i] = " " + b[i];
}
```
## 选项
......@@ -58,17 +108,29 @@ int main() {
### A
```cpp
for (int j = i + 1; j < m; j++)
{
a[i] += " ";
b[i] += " ";
}
```
### B
```cpp
for (int j = i; j <= m; j++)
{
a[i] += " ";
b[i] = " " + b[i];
}
```
### C
```cpp
for (int j = i; j <= m; j++)
{
a[i] += " ";
b[i] += " ";
}
```
\ No newline at end of file
......@@ -6,43 +6,78 @@
输出格式:
在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。
输入样例:
6 2
1 2 3 4 5 6
```json
6 2
1 2 3 4 5 6
```
输出样例:
5 6 1 2 3 4
```json
5 6 1 2 3 4
```
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
int main()
{
int n, m, a[1000];
scanf("%d %d", &n, &m);
m = m % n;
int count = m;
______________
for (int i = 0; i < count; i++)
scanf("%d", &a[i]);
int first = 1;
for (int i = 0; i < n; i++)
{
if (!first)
printf(" ");
printf("%d", a[i]);
first = 0;
}
}
```
## template
```cpp
#include<stdio.h>
#include <stdio.h>
int main()
{
int n,m,a[1000];
scanf("%d %d",&n,&m);
m = m % n;
int count=m;
while(m<n)
{
scanf("%d",&a[m]);
m++;
}
for(int i=0;i<count;i++)
scanf("%d",&a[i]);
int first=1;
for(int i=0;i<n;i++)
{
if(!first)printf(" ");
printf("%d",a[i]);
first=0;
}
int n, m, a[1000];
scanf("%d %d", &n, &m);
m = m % n;
int count = m;
while (m < n)
{
scanf("%d", &a[m]);
m++;
}
for (int i = 0; i < count; i++)
scanf("%d", &a[i]);
int first = 1;
for (int i = 0; i < n; i++)
{
if (!first)
printf(" ");
printf("%d", a[i]);
first = 0;
}
}
```
## 答案
```cpp
while (m < n)
{
scanf("%d", &a[m]);
m++;
}
```
## 选项
......@@ -50,17 +85,29 @@ int main()
### A
```cpp
while (m < n)
{
scanf("%d", &a[m + 1]);
m++;
}
```
### B
```cpp
while (m < n)
{
scanf("%d", &a[m]);
m--;
}
```
### C
```cpp
while (m < n)
{
scanf("%d", &a[m + 1]);
m--;
}
```
\ No newline at end of file
......@@ -2,6 +2,45 @@
<p>在一个数组A中存放100个数据&#xff0c;用子函数判断该数组中哪些是素数&#xff0c;并统计该素数的个数&#xff0c;在主函数中输出该素数的个数</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
#include <stdlib.h>
int isPrime(int n)
{
int i;
if (n < 2)
return 0;
_______________
return 1;
}
int CountPrime(int a[], int size)
{
int i = 0, count = 0;
for (i = 0; i < size; i++)
{
if (isPrime(a[i]))
{
printf("%d ", a[i]);
count++;
if (count % 10 == 0)
printf("\n");
}
}
printf("\n");
return count;
}
int main()
{
int a[100], i, count = 0;
for (i = 0; i < 100; i++)
a[i] = rand() % 1000;
printf("素数的个数:%d\n", CountPrime(a, 100));
return 0;
}
```
## template
```cpp
......@@ -9,45 +48,50 @@
#include <stdlib.h>
int isPrime(int n)
{
int i = 2;
if(n<2) return 0;
for (i=2;i<n;i++)
{
if(n%i == 0)
return 0;
}
return 1;
int i;
if (n < 2)
return 0;
for (i = 2; i * i <= n; ++i)
{
if (n % i == 0)
return 0;
}
return 1;
}
int CountPrime(int a[],int size)
int CountPrime(int a[], int size)
{
int i =0,count = 0;
for (i = 0;i<size;i++)
{
if(isPrime(a[i]))
{
printf("%d ",a[i]);
count++;
if(count%10 == 0)
printf("\n");
}
}
printf("\n");
return count;
int i = 0, count = 0;
for (i = 0; i < size; i++)
{
if (isPrime(a[i]))
{
printf("%d ", a[i]);
count++;
if (count % 10 == 0)
printf("\n");
}
}
printf("\n");
return count;
}
int main()
{
int a[100],i,count = 0;
for(i = 0;i<100;i++)
a[i] = rand()%1000;
printf("素数的个数:%d\n",CountPrime(a,100));
return 0;
int a[100], i, count = 0;
for (i = 0; i < 100; i++)
a[i] = rand() % 1000;
printf("素数的个数:%d\n", CountPrime(a, 100));
return 0;
}
```
## 答案
```cpp
for (i = 2; i * i <= n; ++i)
{
if (n % i == 0)
return 0;
}
```
## 选项
......@@ -55,17 +99,29 @@ int main()
### A
```cpp
for (i = 2; i <= n; ++i)
{
if (n % i == 0)
return 0;
}
```
### B
```cpp
for (i = 2; i * i <= n; ++i)
{
if (n % i == 0)
return 1;
}
```
### C
```cpp
for (i = 2; i * i <= n; ++i)
{
if (n / i == 0)
return 0;
}
```
\ No newline at end of file
# 商品优惠计算器
<p>商品优惠计算器
使用if语句编程实现输入购货金额&#xff0c;输出实际付款金额。购货折扣率如下&#xff1a;
购货金额≤500元 不打折
500元&lt;购货金额≤1000元 9折
使用if语句编程实现输入购货金额&#xff0c;输出实际付款金额。购货折扣率如下&#xff1a;<br />
购货金额≤500元 不打折<br />
500元&lt;购货金额≤1000元 9折<br />
1000元&lt;购货金额 8折</p>
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
float money = 0.0;
float pay = 0.0;
bool run = true;
while (run)
{
printf("\n请输入购货金额:\n");
scanf("%f", &money);
____________________
}
return 0;
}
```
## template
```cpp
......@@ -17,36 +41,49 @@
#include <unistd.h>
int main()
{
float money=0.0;
float pay=0.0;
bool run = true;
while(run)
{
printf("\n请输入购货金额:\n");
scanf("%f", &money);
if(money >1000)
{
pay=money*0.8;
printf("打八折,应付金额:%.2f\n",pay);
}
else if((money >500)&&(money <=1000))
{
pay=money*0.9;
printf("打九折,应付金额:%.2f\n",pay);
}
else if(money <=500)
{
printf("不打折,应付金额:%.2f\n",money);
}
}
return 0;
float money = 0.0;
float pay = 0.0;
bool run = true;
while (run)
{
printf("\n请输入购货金额:\n");
scanf("%f", &money);
if (money > 1000)
{
pay = money * 0.8;
printf("打八折,应付金额:%.2f\n", pay);
}
else if ((money > 500) && (money <= 1000))
{
pay = money * 0.9;
printf("打九折,应付金额:%.2f\n", pay);
}
else if (money <= 500)
{
printf("不打折,应付金额:%.2f\n", money);
}
}
return 0;
}
```
## 答案
```cpp
if (money > 1000)
{
pay = money * 0.8;
printf("打八折,应付金额:%.2f\n", pay);
}
else if ((money > 500) && (money <= 1000))
{
pay = money * 0.9;
printf("打九折,应付金额:%.2f\n", pay);
}
else if (money <= 500)
{
printf("不打折,应付金额:%.2f\n", money);
}
```
## 选项
......@@ -54,17 +91,56 @@ int main()
### A
```cpp
if (money > 1000)
{
pay = money * 0.8;
printf("打八折,应付金额:%.2f\n", pay);
}
elif ((money > 500) && (money <= 1000))
{
pay = money * 0.9;
printf("打九折,应付金额:%.2f\n", pay);
}
elif (money <= 500)
{
printf("不打折,应付金额:%.2f\n", money);
}
```
### B
```cpp
if (money > 1000)
{
pay = money * 0.8;
printf("打八折,应付金额:%.2f\n", pay);
}
else ((money > 500) && (money <= 1000))
{
pay = money * 0.9;
printf("打九折,应付金额:%.2f\n", pay);
}
else (money <= 500)
{
printf("不打折,应付金额:%.2f\n", money);
}
```
### C
```cpp
if (money > 1000):
{
pay = money * 0.8;
printf("打八折,应付金额:%.2f\n", pay);
}
if ((money > 500) && (money <= 1000)):
{
pay = money * 0.9;
printf("打九折,应付金额:%.2f\n", pay);
}
if (money <= 500):
{
printf("不打折,应付金额:%.2f\n", money);
}
```
\ No newline at end of file
# 移动数组中的元素
题目描述
将一维数组中的元素循环左移 k 个位置
输入描述
第 1 行是一维数组元素的个数 n (数组大小)
第 2 行是一个整数 k , 表示移动的位置
下面 n 行为数组的元素个数
输出描述
输出 n 行,表示移动后的数字
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
#define N 10000
int main()
{
int k, a[N], b[N], n, t, w, i;
scanf("%d", &n);
scanf("%d", &k);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < k % n; i++)
b[i] = a[i];
for (i = 0; i < n; i++)
{
__________________
}
for (i = 0; i < n; i++)
printf("%d\n", a[i]);
return 0;
}
```
## template
```cpp
#include<stdio.h>
#include <stdio.h>
#define N 10000
int main()
{
int k,a[N],b[N],n,t,w,i;
scanf("%d",&n);
scanf("%d",&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for (i = 0; i < k % n; i++)
b[i] = a[i];
for (i = 0; i < n; i++)
{
if (i < n - k % n)
a[i] = a[i + k % n];
else
a[i] = b[i - n + k % n];
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
return 0;
int k, a[N], b[N], n, t, w, i;
scanf("%d", &n);
scanf("%d", &k);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < k % n; i++)
b[i] = a[i];
for (i = 0; i < n; i++)
{
if (i < n - k % n)
a[i] = a[i + k % n];
else
a[i] = b[i - n + k % n];
}
for (i = 0; i < n; i++)
printf("%d\n", a[i]);
return 0;
}
```
## 答案
```cpp
if (i < n - k % n)
a[i] = a[i + k % n];
else
a[i] = b[i - n + k % n];
```
## 选项
......@@ -47,17 +81,26 @@ int main()
### A
```cpp
if (i < n - k % n)
a[i] = a[i + k + n];
else
a[i] = b[i + k - n];
```
### B
```cpp
if (i < n - k % n)
a[i] = a[i + k % n];
else
a[i] = b[i - n + k];
```
### C
```cpp
if (i < n - k % n)
a[i] = a[i + k - n];
else
a[i] = b[i - n + k % n];
```
\ No newline at end of file
# 个位数是6,且能被3整除的五位数共有多少个?
<p>要求:
1、必须包含循环结构、顺序结构、选择分支结构。
2、必须包含数组
3、必须包含一个以上函数
4、可以包含方针</p>
请你直接选择出正确答案
## template
```cpp
#include <iostream>
using namespace std;
void search1(){
int i,t=0;
for(i=10000;i<=99999;i++){
if(i%3==0&&i%10==6)
t++;
}
cout<<t;
void search1()
{
int i, t = 0;
for (i = 10000; i <= 99999; i++)
{
if (i % 3 == 0 && i % 10 == 6)
t++;
}
cout << t;
}
int main()
{
search1();
return 0;
search1();
return 0;
}
```
## 答案
```cpp
3000
```
## 选项
......@@ -37,17 +35,17 @@ int main()
### A
```cpp
2000
```
### B
```cpp
3096
```
### C
```cpp
2048
```
\ No newline at end of file
# 一个整数的序列,要求对其重新排序
# 冒泡排序法排序
<p>一个整数的序列&#xff0c;要求对其重新排序。排序要求:
1.奇数在前&#xff0c;偶数在后&#xff1b;
2.奇数按从大到小排序&#xff1b;
3.偶数按从小到大排序。<br />
输入一行&#xff0c;包含整数个数n&#xff0c; n个整数值&#xff0c;彼此以一个空格分开。
按照要求排序后输出一行&#xff0c;包含排序后的n 个整数。
 </p>
输入n(1≤n≤10)个整数,用冒泡排序法对其从小到大排序,共进行n-1趟,要求输出每一趟的排序情况
## template
输入格式:
先输入个数n,再输入n个整数。
输出格式:
第1趟结果
第2趟结果
......
第n-1趟结果
每个数后面有一个空格,每个序列占一行。
输入样例:
```json
5
4 2 3 2 1
```
输出样例:
```json
2 3 2 1 4
2 2 1 3 4
2 1 2 3 4
1 2 2 3 4
```
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a, int b){
    int x = a % 2;
    int y = b % 2;
    if(x == y)
        if(x == 0)
            return a < b;
        else
            return a > b;
    else
        return x > y;
#include "stdio.h"
int main()
{
int arr[10];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
____________________
}
}
for (int j = 0; j < n; j++)
printf("%d ", arr[j]);
printf("\n");
}
return 0;
}
```
## template
```cpp
#include "stdio.h"
int main()
{
    int n, i;
    cin >> n;
    int a[n];
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n, cmp);
    for(i = 0; i < n; i++)
        cout << a[i] << " ";
int arr[10];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
for (int j = 0; j < n; j++)
printf("%d ", arr[j]);
printf("\n");
}
return 0;
}
```
## 答案
```cpp
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
```
## 选项
......@@ -49,17 +105,23 @@ int main()
### A
```cpp
int t = arr[j];
arr[j + 1] = t;
arr[j] = arr[j + 1];
```
### B
```cpp
arr[j] = arr[j + 1];
int t = arr[j];
arr[j + 1] = t;
```
### C
```cpp
int t = arr[j];
arr[j + 1] = arr[j];
arr[j] = t;
```
\ No newline at end of file
......@@ -2,48 +2,90 @@
给出一个由O和X组成的串,长度为1~80,统计得分,每个O的得分为目前连续出现的O的个数,X的得分为0,例如OOXXO的得分为1+2+0+0+1.
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
int main()
{
char s[85];
int score = 0, x;
scanf("%s", &s);
for (int i = 0; s[i]; i++)
{
if (s[i] == 'X')
score += 0;
if (s[i] == 'O')
{
int temp = 1;
if (i == 0)
score += 1;
else
{
x = i;
while (x > 0)
{
________________
}
score += temp;
}
}
}
printf("%d\n", score);
return 0;
}
```
## template
```cpp
#include"stdlib.h"
#include"string.h"
#include"stdio.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
int main()
{
char s[85];
int score = 0,x;
scanf("%s",&s);
for (int i = 0;s[i];i++)
{
if (s[i] == 'X')
score += 0;
if (s[i] == 'O')
{
int temp = 1;
if (i == 0)score += 1;
else
{
x=i;
while (x > 0)
{
if (s[x - 1] == 'O')temp++;
else break;
x--;
}
score += temp;
}
}
}
printf("%d\n", score);
system("pause");
return 0;
char s[85];
int score = 0, x;
scanf("%s", &s);
for (int i = 0; s[i]; i++)
{
if (s[i] == 'X')
score += 0;
if (s[i] == 'O')
{
int temp = 1;
if (i == 0)
score += 1;
else
{
x = i;
while (x > 0)
{
if (s[x - 1] == 'O')
temp++;
else
break;
x--;
}
score += temp;
}
}
}
printf("%d\n", score);
return 0;
}
```
## 答案
```cpp
if (s[x - 1] == 'O')
temp++;
else
break;
x--;
```
## 选项
......@@ -51,17 +93,23 @@ int main()
### A
```cpp
if (s[x - 1] == 'O')
temp++;
else
break;
```
### B
```cpp
if (s[x - 1] == 'O')
temp++;
```
### C
```cpp
if (s[x - 1] == 'O')
temp++;
x--;
```
\ No newline at end of file
# 一个班有10个同学,通过键盘输入成绩,并打印输出,每行输出5个同学的成绩。并求出平均成绩,最高分、最低分并输出。
<p>一个班有10个同学&#xff0c;通过键盘输入成绩&#xff0c;
并打印输出&#xff0c;每行输出5个同学的成绩。并求出平均成绩&#xff0c;最高分、最低分并输出。算法分析&#xff1a;
(1)定义一个数组用来存放10个成绩数据。
(2)用循环结构实现成绩输入&#xff1b;
(3)用循环结构实现成绩输出,并控制换行&#xff1b;
并打印输出&#xff0c;每行输出5个同学的成绩。并求出平均成绩&#xff0c;最高分、最低分并输出。算法分析&#xff1a;<br />
(1)定义一个数组用来存放10个成绩数据。<br />
(2)用循环结构实现成绩输入&#xff1b;<br />
(3)用循环结构实现成绩输出,并控制换行&#xff1b;<br />
(4)使用循环结构求平均成绩、最高分、最低分并输出。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#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);
}
```
## template
```cpp
......@@ -38,7 +63,10 @@ int main(){
## 答案
```cpp
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
```
## 选项
......@@ -46,17 +74,26 @@ int main(){
### A
```cpp
if(max>a[i])
max=a[i];
if(min<a[i])
min=a[i];
```
### B
```cpp
if(max<a[i])
max=a[i + 1];
if(min>a[i])
min=a[i - 1];
```
### C
```cpp
if(max<a[i])
min=a[i];
if(min>a[i])
max=a[i];
```
\ No newline at end of file
......@@ -23,49 +23,106 @@ a,b均为自然数
1
WA</code></pre>
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
int main()
{
int a;
int b;
char operation;
int num;
while (scanf("%d", &a) != EOF)
{
scanf("%c", &operation);
scanf("%d", &b);
if (operation == '+')
{
num = a + b;
printf("%d\n", num);
}
else if (operation == '-')
{
num = a - b;
printf("%d\n", num);
}
else if (operation == '*')
{
num = a * b;
printf("%d\n", num);
}
_________________________
else
{
printf("%s\n", "WA");
}
}
return 0;
}
```
## template
```cpp
#include<stdio.h>
#include <stdio.h>
int main()
{
int a;
int b;
char operation;
int num;
while (scanf("%d", &a) != EOF)
{
scanf("%c", &operation);
scanf("%d", &b);
if (operation == '+')
{
num = a + b;
printf("%d\n", num);
}
else if (operation == '-') {
num = a - b;
printf("%d\n", num);
}
else if (operation == '*') {
num = a * b;
printf("%d\n", num);
}
else if (operation == '/' && b != 0) {
num = a / b;
printf("%d\n", num);
}
else {
printf("%s\n", "WA");
}
}
return 0;
int a;
int b;
char operation;
int num;
while (scanf("%d", &a) != EOF)
{
scanf("%c", &operation);
scanf("%d", &b);
if (operation == '+')
{
num = a + b;
printf("%d\n", num);
}
else if (operation == '-')
{
num = a - b;
printf("%d\n", num);
}
else if (operation == '*')
{
num = a * b;
printf("%d\n", num);
}
else if (operation == '/' && b != 0)
{
num = a / b;
printf("%d\n", num);
}
else if (operation == '%' && b != 0)
{
num = a % b;
printf("%d\n", num);
}
else
{
printf("%s\n", "WA");
}
}
return 0;
}
```
## 答案
```cpp
else if (operation == '/' && b != 0)
{
num = a / b;
printf("%d\n", num);
}
else if (operation == '%' && b != 0)
{
num = a % b;
printf("%d\n", num);
}
```
## 选项
......@@ -73,17 +130,44 @@ int main()
### A
```cpp
else if (operation == '/')
{
num = a / b;
printf("%d\n", num);
}
else if (operation == '%')
{
num = a % b;
printf("%d\n", num);
}
```
### B
```cpp
else if (operation == '/' && b != 0)
{
num = a / b;
printf("%d\n", num);
}
else if (operation == '%')
{
num = a % b;
printf("%d\n", num);
}
```
### C
```cpp
else if (operation == '/')
{
num = a / b;
printf("%d\n", num);
}
else if (operation == '%' && b != 0)
{
num = a % b;
printf("%d\n", num);
}
```
\ No newline at end of file
# 输入两个小写英语字母后, 输出两个字母的差
两个小写字母的差用整数输出。
但是,输入小写以外的文字就结束程序。
比较两个字母的部分用diff这个名字的函数书写。执行结果
请输入两个小写:a b
字母a和字母b的区别是1。
请输入两个小写:f b
字母f和字母b的差异是4。
字母f和字母b的差是4。
请输入两个小写:0 a
退出程序。
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <iostream>
using namespace std;
int diff(char ch1, char ch2)
{
__________________
}
int main()
{
char a, b;
while (1)
{
cout << "请输入两个小写:";
cin >> a >> b;
if (a > 'z' || a < 'a' || b > 'z' || b < 'a')
break;
cout << "文字" << a << "和文字" << b << "的差是" << diff(a, b) << "。\n";
}
return 0;
}
```
## template
```cpp
......@@ -17,26 +49,30 @@
using namespace std;
int diff(char ch1, char ch2)
{
if (ch1 > ch2) return ch1 - ch2; else return ch2 - ch1;
if (ch1 > ch2)
return ch1 - ch2;
else
return ch2 - ch1;
}
int main()
{
char a, b;
while (1)
{
cout << "请输入两个小写:";
cin >> a >> b;
if (a > 'z' || a < 'a' || b > 'z' || b < 'a') break;
cout << "文字" << a << "和文字" << b << "的差异是" << diff(a, b) << "。\n";
}
return 0;
char a, b;
while (1)
{
cout << "请输入两个小写:";
cin >> a >> b;
if (a > 'z' || a < 'a' || b > 'z' || b < 'a')
break;
cout << "文字" << a << "和文字" << b << "的差是" << diff(a, b) << "。\n";
}
return 0;
}
```
## 答案
```cpp
return abs(ch1 - ch2);
```
## 选项
......@@ -44,17 +80,20 @@ int main()
### A
```cpp
return ch1 - ch2;
```
### B
```cpp
return ch2 - ch1;
```
### C
```cpp
if (ch1 < ch2)
return ch1 - ch2;
else
return ch2 - ch1;
```
\ No newline at end of file
# 排序
试题描述
由键盘上输入n个整数,请将这些数从大到小排序,然后输出排序后的数列。
由键盘上输入n个整数,请将这些数从大到小排序,然后输出排序后的数列。
输入
输入包含两行:
第一行是n(1 <= n <= 1000)。
第二行是n个整数,邻近两数之间用一个空格隔开。
输入包含两行:
第一行是n(1 <= n <= 1000)。
第二行是n个整数,邻近两数之间用一个空格隔开。
输出
输出排序后的n个整数,邻近两数之间用一个空格隔开。
输出排序后的n个整数,邻近两数之间用一个空格隔开。
输入示例
5
8 2 5 1 2
```json
5
8 2 5 1 2
```
输出示例
8 5 2 2 1
```json
8 5 2 2 1
```
数据范围
输入和输出均为int范围的整数
输入和输出均为int范围的整数
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <iostream>
using namespace std;
int main()
{
int n, tmp;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
__________________
}
}
for (int i = 0; i < n; i++)
{
cout << a[i];
if (i != n - 1)
cout << " ";
}
return 0;
}
```
## template
```cpp
#include<iostream>
#include <iostream>
using namespace std;
int main() {
int n,tmp;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j]) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
for (int i = 0; i < n; i++) {
cout << a[i];
if (i != n - 1)
cout << " ";
}
return 0;
int main()
{
int n, tmp;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] < a[j])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
for (int i = 0; i < n; i++)
{
cout << a[i];
if (i != n - 1)
cout << " ";
}
return 0;
}
```
## 答案
```cpp
if (a[i] < a[j])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
```
## 选项
......@@ -56,17 +112,32 @@ int main() {
### A
```cpp
if (a[i] > a[j])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
```
### B
```cpp
if (a[i] < a[j])
{
a[i] = a[j];
tmp = a[i];
a[j] = tmp;
}
```
### C
```cpp
if (a[i] > a[j])
{
a[i] = a[j];
tmp = a[i];
a[j] = tmp;
}
```
\ No newline at end of file
# 字符数组
<p>编写一个以两个字符数组作为输入的函数。
如果第二个数组包含在第一个数组中&#xff0c;则函数返回第一个数组中第二个数组开始的第一个索引。
如果第二个数组不被包含在第一个数组&#xff0c;然后函数应该return -1
输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’l’,’l’]  就 return 1.
<p>编写一个以两个字符数组作为输入的函数。<br />
如果第二个数组包含在第一个数组中&#xff0c;则函数返回第一个数组中第二个数组开始的第一个索引。<br />
如果第二个数组不被包含在第一个数组&#xff0c;然后函数应该return -1<br />
输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’l’,’l’] 就 return 1.<br />
输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’n’] 就 return -1.</p>
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
char a[128], b[128];
int numA, numB;
cout << "请输入第一个数组元素个数:";
cin >> numA;
cout << "请输入第一个数组元素:";
for (int i = 0; i < numA; ++i)
cin >> a[i];
cin.clear();
cin.sync();
cout << "请输入第二个数组元素个数:";
cin >> numB;
cout << "请输入第二个数组元素:";
for (int i = 0; i < numB; ++i)
cin >> b[i];
int num = 0;
string index;
for (int j = 0; j < numB; j++)
{
for (int k = 0; k < numA; k++)
{
if (b[j] == a[k])
{
__________________
}
}
}
if (num == numB)
{
cout << "第二个数组包含在第一个数组中" << endl;
cout << "第一个数组中第二个数组开始的第一个索引为:" << index.substr(0, 1) << endl;
}
else
cout << "第二个数组不被包含在第一个数组";
system("pause");
return 0;
}
```
## template
```cpp
......@@ -14,50 +60,52 @@
using namespace std;
int main()
{
char a[128],b[128];
int numA, numB;
cout << "请输入第一个数组元素个数:";
cin >> numA;
cout << "请输入第一个数组元素:";
for (int i = 0; i < numA; ++i)
cin >> a[i];
cin.clear();
cin.sync();
cout << "请输入第二个数组元素个数:";
cin >> numB;
cout << "请输入第二个数组元素:";
for (int i = 0; i < numB; ++i)
cin >> b[i];
int num = 0;
string index;
for (int j = 0; j < numB; j++)
{
for (int k = 0; k < numA; k++)
{
if (b[j] == a[k])
{
index += to_string(k);
num++;
break;
}
}
}
if (num == numB)
{
cout << "第二个数组包含在第一个数组中" << endl;
cout << "第一个数组中第二个数组开始的第一个索引为:" << index.substr(0,1) << endl;
}
else
cout << "第二个数组不被包含在第一个数组";
system("pause");
return 0;
char a[128], b[128];
int numA, numB;
cout << "请输入第一个数组元素个数:";
cin >> numA;
cout << "请输入第一个数组元素:";
for (int i = 0; i < numA; ++i)
cin >> a[i];
cin.clear();
cin.sync();
cout << "请输入第二个数组元素个数:";
cin >> numB;
cout << "请输入第二个数组元素:";
for (int i = 0; i < numB; ++i)
cin >> b[i];
int num = 0;
string index;
for (int j = 0; j < numB; j++)
{
for (int k = 0; k < numA; k++)
{
if (b[j] == a[k])
{
index += to_string(k);
num++;
break;
}
}
}
if (num == numB)
{
cout << "第二个数组包含在第一个数组中" << endl;
cout << "第一个数组中第二个数组开始的第一个索引为:" << index.substr(0, 1) << endl;
}
else
cout << "第二个数组不被包含在第一个数组";
system("pause");
return 0;
}
```
## 答案
```cpp
index += to_string(k);
num++;
break;
```
## 选项
......@@ -65,17 +113,21 @@ int main()
### A
```cpp
index += to_string(k);
num++;
```
### B
```cpp
index = to_string(k);
num++;
```
### C
```cpp
index = to_string(k);
num++;
break;
```
\ No newline at end of file
......@@ -4,36 +4,64 @@
输入:B<回车>
输出:B在第2个位置,其后面第四个字母是F
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
int main()
{
char c, c2;
printf("输入:");
c = getchar();
int m = 0, n = 0;
if (c >= 'A' && c <= 'z')
{
m = c - 'A' + 1;
_____________________
}
if (n > 0)
printf("%c在第%d个位置,其后面第四个字母是%c\n", c, m, c2);
else
printf("%c在第%d个位置,其后面没有第四个字母\n", c, m);
return 0;
}
```
## template
```cpp
#include <stdio.h>
int main(){
char c,c2;
printf("输入:");
c = getchar();
int m=0,n=0;
if(c>='A'&& c<='z')
{
m = c - 'A' + 1;
if(m < 23)
{
c2 = c + 4;
n = m+4;
}
}
if(n > 0)
printf("%c在第%d个位置,其后面第四个字母是%c\n",c,m,c2);
else
printf("%c在第%d个位置,其后面没有第四个字母\n",c,m);
return 0;
int main()
{
char c, c2;
printf("输入:");
c = getchar();
int m = 0, n = 0;
if (c >= 'A' && c <= 'z')
{
m = c - 'A' + 1;
if (m < 23)
{
c2 = c + 4;
n = m + 4;
}
}
if (n > 0)
printf("%c在第%d个位置,其后面第四个字母是%c\n", c, m, c2);
else
printf("%c在第%d个位置,其后面没有第四个字母\n", c, m);
return 0;
}
```
## 答案
```cpp
if (m < 23)
{
c2 = c + 4;
n = m + 4;
}
```
## 选项
......@@ -41,17 +69,29 @@ int main(){
### A
```cpp
if (m <= 23)
{
c2 = c + 4;
n = m + 4;
}
```
### B
```cpp
if (m > 23)
{
c2 = c + 4;
n = m + 4;
}
```
### C
```cpp
if (m >= 23)
{
c2 = c + 4;
n = m + 4;
}
```
\ No newline at end of file
......@@ -2,6 +2,41 @@
<p>&nbsp;给你一个整数数组 arr 。请你将数组中的元素按照其二进制表示中,数字 1 的数目升序排序。 如果存在多个数字二进制中 1 的数目相同,则必须将它们按照数值大小升序排列。请你返回排序后的数组。</p>
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include<stdio.h>
#include<stdlib.h>
int oneNum(int x)
{
int cnt = 0;
while(x)
{
____________
}
return cnt;
}
int cmp(const void *a,const void*b)
{
int al,bl;
int ret;
al = *(int*)a;
bl = *(int*)b;
ret = oneNum(al) - oneNum(bl);
return ret ? ret : al - bl;
}
int main()
{
int s[]={1,2,3,5,6,7,8},i;
int len = sizeof(s)/sizeof(*s);
qsort(s,len,4,cmp);
for(i = 0 ; i < len ; i++)
{
printf("%d\n",s[i]);
}
}
```
## template
```cpp
......@@ -41,7 +76,8 @@ int main()
## 答案
```cpp
cnt++;
x = x & (x - 1);
```
## 选项
......@@ -49,17 +85,20 @@ int main()
### A
```cpp
cnt++;
x = x | (x - 1);
```
### B
```cpp
cnt++;
x = x & (x + 1);
```
### C
```cpp
cnt++;
x = x & x - 1;
```
\ No newline at end of file
# 检查一个3位数是否是水仙花数
检查一个3位数是否是水仙花数。
输入:一个数字,比如 371,输出:x是水仙花数,
如果不是,则输出:x不是水仙花数。
注:x为输入的数字
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#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;
}
```
## template
```cpp
#include <iostream>
#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;
system("pause");
return 0;
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;
}
```
## 答案
```cpp
y = a * a * a + b * b * b + c * c * c;
```
## 选项
......@@ -37,17 +63,17 @@ int main()
### A
```cpp
y = a * a + b * b + c * c;
```
### B
```cpp
y = a * a * a * a + b * b * b * b + c * c * c * c;
```
### C
```cpp
y = a * b * c;
```
\ No newline at end of file
# 秒数转换
输入一个秒数,转换成HH:MM:SS的格式输出。
输入样例
365
输出样例
00:06:05
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <cstdio>
int n;
void print(int x)
{
if (x == 0)
printf("00");
else if (x < 10)
printf("0%d", x);
else
printf("%d", x);
return;
}
int main()
{
scanf("%d", &n);
int s, f, m;
____________
print(s);
printf(":");
print(f);
printf(":");
print(m);
return 0;
}
```
## template
```cpp
#include<cstdio>
#include <cstdio>
int n;
void print(int x){
if(x==0)printf("00");
else if(x<10)printf("0%d",x);
else printf("%d",x);
return;
void print(int x)
{
if (x == 0)
printf("00");
else if (x < 10)
printf("0%d", x);
else
printf("%d", x);
return;
}
int main(){
scanf("%d",&n);
int s,f,m;
s=n/3600;
f=n/60%60;
m=n%60;
print(s);
printf(":");
print(f);
printf(":");
print(m);
return 0;
int main()
{
scanf("%d", &n);
int s, f, m;
s = n / 3600;
f = n / 60 % 60;
m = n % 60;
print(s);
printf(":");
print(f);
printf(":");
print(m);
return 0;
}
```
## 答案
```cpp
s = n / 3600;
f = n / 60 % 60;
m = n % 60;
```
## 选项
......@@ -43,17 +83,23 @@ int main(){
### A
```cpp
s = n / 3600;
f = n / 60 / 60;
m = n / 60;
```
### B
```cpp
s = n / 3600;
f = n % 60 % 60;
m = n % 60;
```
### C
```cpp
s = n / 3600;
f = n / 60 % 60;
m = n / 60;
```
\ No newline at end of file
# 找出string中只出现过一次的字符
# 找出字符串中第一个只出现一次的字符
找出string中只出现过一次的字符
例如"abcdef abcd"中需要得到ef
输入描述:
输入一个非空字符串
输出描述:
输出第一个只出现一次的字符,如果不存在输出-1
示例1
输入:
```json
asdfasdfo
```
输出:
```json
o
```
以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
while (getline(cin, str))
{
int a[256] = {0};
bool flag = false;
for (int i = 0; i < str.size(); ++i)
____________________
for (int i = 0; i < str.size(); ++i)
{
if (a[str[i]] == 1)
{
cout << str[i] << endl;
flag = true;
break;
}
}
if (flag == false)
cout << "-1" << endl;
}
return 0;
}
```
## template
......@@ -11,31 +61,33 @@
using namespace std;
int main()
{
    string temp = "";
    cout << "请输入字符串:";
    cin >> temp;
    string str = "";        
    string str1 = "";        
    for (int i = 0; i < temp.length(); i++)
    {
        string tempSub = temp.substr(i, 1);    
        int b = temp.rfind(tempSub);                
        if (i == b && str1.find(tempSub) == -1)        
            str +=temp.substr(i, 1);
        else if (str1.find(tempSub) == -1)
            str1 += temp.substr(i, 1);
    }
    cout << "只出现一次的字符:" << str << endl;
    cout << "重复出现的字符的字符:" << str1 << endl;
    system("pause");
    return 0;
string str;
while (getline(cin, str))
{
int a[256] = {0};
bool flag = false;
for (int i = 0; i < str.size(); ++i)
++a[str[i]];
for (int i = 0; i < str.size(); ++i)
{
if (a[str[i]] == 1)
{
cout << str[i] << endl;
flag = true;
break;
}
}
if (flag == false)
cout << "-1" << endl;
}
return 0;
}
```
## 答案
```cpp
++a[str[i]];
```
## 选项
......@@ -43,17 +95,17 @@ int main()
### A
```cpp
a[str[i]]++;
```
### B
```cpp
a[str[i]++];
```
### C
```cpp
a[str[i]--];
```
\ No newline at end of file
......@@ -2,6 +2,29 @@
<p>本关任务&#xff1a;编写程序&#xff0c;有五种水果&#xff0c;apple、banana、orage、strawberry、pear&#xff0c;每一种有一个价格&#xff08;浮点小数&#xff09;&#xff0c;由老板输入&#xff0c;请提示用户选择什么水果&#xff0c;购买数量&#xff08;按照斤两&#xff09;&#xff0c;然后将总价显示出来。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include<stdio.h>
int main(){
typedef enum {apple, banana, orange, strawberry, pear} fruits;
double prices[5];
fruits purchase;
int fruit;
double amount;
for(int i = 0; i < 5; i++)
scanf("%lf", &prices[i]);
printf("水果编号:1.苹果 2.香蕉 3.橘子 4.草莓 5.梨\n");
printf("请输入购买的水果(1~5),以及购买数量(按照斤两):\n");
scanf("%d %lf", &fruit, &amount);
purchase = (fruits)fruit;
________________________
return 0;
}
```
## template
```cpp
......@@ -26,7 +49,7 @@ int main(){
## 答案
```cpp
printf("总价为:%.3lf", prices[purchase-1]*amount);
```
## 选项
......@@ -34,17 +57,17 @@ int main(){
### A
```cpp
printf("总价为:%.3lf", prices[purchase]*amount);
```
### B
```cpp
printf("总价为:%.3lf", prices(purchase-1)*amount);
```
### C
```cpp
printf("总价为:%.3lf", prices(purchase)*amount);
```
\ No newline at end of file
......@@ -2,6 +2,35 @@
求10-100之间个位数为7的质数
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
int isp(int n)
{
int i;
if (n<2)
return 0;
for (i=2;i*i<=n;++i)
{
_______________
}
return 1;
}
int main()
{
int i=17;
while (i<=100)
{
if (isp(i))
printf("%d ",i);
i+=10;
}
printf("\n");
return 0;
}
```
## template
```cpp
......@@ -35,7 +64,8 @@ int main()
## 答案
```cpp
if (n%i==0)
return 0;
```
## 选项
......@@ -43,17 +73,20 @@ int main()
### A
```cpp
if (n%i==0)
return 1;
```
### B
```cpp
if (n/i==0)
return 1;
```
### C
```cpp
if (n/i==0)
return 0;
```
\ No newline at end of file
# 数据合并
题目描述
将两个从小到大排列的一维数组 (维长分别为 m,n , 其中 m,n≤100) 仍按从小到大的排列顺序合并到一个新的一维数组中,输出新的数组.
输入描述
第 1行一个正整数 m , 表示第一个要合并的一维数组中的元素个数
第 1 行一个正整数 m , 表示第一个要合并的一维数组中的元素个数
第 2 行一个正整数 n , 表示第二个要合并的一维数组中的元素个数
第 3 行输入 m 个整数 (每个数用空格分开) , 表示第一个数组元素的值.
第 4 行输入 n 个整数 (每个数用空格分开) , 表示第二个数组元素的值.
输出描述
一行,表示合并后的数据,共 m +n 个数
样例输入
```json
3
4
1 3 5
2 4 6 8
```
样例输出
```json
1 2 3 4 5 6 8
要多组输入输出
```
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <iostream>
using namespace std;
void merge(int * a1, int m, int * a2, int n)
{
int m1 = m - 1;
int n1 = n - 1;
for (int i = m + n - 1; i >= 0; i--)
{
if (m1 < 0) a1[i] = a2[n1--];
else if (n1 < 0) a1[i] = a1[m1--];
__________________
}
}
int main()
{
int m;
int n;
cin >> m;
cin >> n;
int a1[201];
int a2[101];
for (int i = 0; i < m; i++) cin >> a1[i];
for (int i = 0; i < n; i++) cin >> a2[i];
merge(a1, m, a2, n);
for (int i = 0; i < m + n; i++) cout << a1[i] << " ";
return 0;
}
```
## template
......@@ -54,7 +102,8 @@ int main()
## 答案
```cpp
else if (a1[m1] < a2[n1]) a1[i] = a2[n1--];
else a1[i] = a1[m1--];
```
## 选项
......@@ -62,17 +111,20 @@ int main()
### A
```cpp
else if (a1[m1] < a2[n1]) a1[i] = a2[n1];
else a1[i] = a1[m1];
```
### B
```cpp
else if (a1[m1] > a2[n1]) a1[i] = a2[n1--];
else a1[i] = a1[m1--];
```
### C
```cpp
else if (a1[m1] > a2[n1]) a1[i] = a2[n1];
else a1[i] = a1[m1];
```
\ No newline at end of file
# 计算所有4位正整数中同时能被13和20整除的数的和
<p>计算所有4位正整数中同时能被13和20整除的数的和&#xff0c; 并同时做到如下显示:
①显示这些数:
②显示这些数的个数:
<p>计算所有4位正整数中同时能被13和20整除的数的和&#xff0c; 并同时做到如下显示:<br />
①显示这些数:<br />
②显示这些数的个数:<br />
③显示这些数的和。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include "stdio.h"
int main()
{
int i = 1000;
int count = 0;
int sum = 0;
printf("所有4位正整数中同时能被13和20整除的数:\n");
for(i = 1000;i<10000;i++)
{
if(_________________)
{
count++;
sum = sum + i;
printf("%d、",i);
}
}
printf("\n这些数一共有%d个\n",count);
printf("这些数的和是:%d\n",sum);
}
```
## template
```cpp
......@@ -32,7 +56,7 @@ int main()
## 答案
```cpp
i % 13 == 0 && i % 20 == 0
```
## 选项
......@@ -40,17 +64,17 @@ int main()
### A
```cpp
i / 13 == 0 && i / 20 == 0
```
### B
```cpp
i % 13 == 0 & i % 20 == 0
```
### C
```cpp
(i % 13 == 0) & (i % 20 == 0)
```
\ No newline at end of file
......@@ -2,6 +2,33 @@
<p>实现从键盘输入一个字符时&#xff0c;如果该字符为小写字母&#xff0c;则转换为大写字母输出&#xff1b;如果该字符为大写字母&#xff0c;则转换为小写字母输出&#xff1b;如果为其他字符&#xff0c;则原样输出。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include<stdio.h>
int main()
{
char x,y;
printf("请输入一个字符:");
scanf("%c",&x);
if(x>='A'&&x<='Z')
{
(1)___________
printf("此字母是一个大写字母,转换后的小写字母是:%c",y);
}
else if(x>='a'&&x<='z')
{
(2)___________
printf("此字母是一个小写字母,转换后的大写字母是%c",y);
}
else
{
printf("%c",x);
}
return 0;
}
```
## template
```cpp
......@@ -32,7 +59,8 @@ int main()
## 答案
```cpp
(1):y=x+32;
(2):y=x-32;
```
## 选项
......@@ -40,17 +68,20 @@ int main()
### A
```cpp
(1):y=x-32;
(2):y=x+32;
```
### B
```cpp
(1):y=x+31;
(2):y=x-31;
```
### C
```cpp
(1):y=x-31;
(2):y=x+31;
```
\ No newline at end of file
......@@ -9,6 +9,34 @@
输出格式:
输出一个正整数&#xff0c;是上述序列中所有素数之和。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include <stdio.h>
int isprime( int n);
int main()
{
int i,n,m,s=0;
scanf("%d", &n);
for( i=0; i<n; i++ ) {
scanf("%d", &m);
if(isprime(m)){
s+=m;
}
}
printf("%d", s);
return 0;
}
int isprime(int n)
{
int i;
if(n<=1) return 0;
for(i=2;i*i<=n;i++)
_______________
return 1;
}
```
## template
```cpp
......@@ -40,7 +68,7 @@ int isprime(int n)
## 答案
```cpp
if(n%i==0) return 0;
```
## 选项
......@@ -48,17 +76,17 @@ int isprime(int n)
### A
```cpp
if(n/i==0) return 0;
```
### B
```cpp
if(n%i==0) return 1;
```
### C
```cpp
if(n%i==1) return 0;
```
\ No newline at end of file
......@@ -7,6 +7,32 @@
输出
只有一行且只有一个整数&#xff0c;乐乐班级的总分数。</p>
以下程序实现了这一功能,请你填补空白处内容:
```cpp
#include<stdio.h>
int main()
{
int a[10005];
long long t=0;
int n,i,j,x;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
_____________
}
}
for(i=0;i<n;i++)
{
t+=a[i]*(i+1);
}
printf("%lld",t);
return 0;
}
```
## template
```cpp
......@@ -40,7 +66,11 @@ int main()
## 答案
```cpp
if(a[i]>a[j]){
x=a[i];
a[i]=a[j];
a[j]=x;
}
```
## 选项
......@@ -48,17 +78,29 @@ int main()
### A
```cpp
if(a[i]<a[j]){
x=a[i];
a[i]=a[j];
a[j]=x;
}
```
### B
```cpp
if(a[i]>a[j]){
x=a[i];
a[j]=x;
a[i]=a[j];
}
```
### C
```cpp
if(a[i]<a[j]){
x=a[i];
a[j]=x;
a[i]=a[j];
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册