# 2021级C++上机考（物联网、机器人）（上）

*上都是水题，看看就好

## 一、This is line x

3

This is line 1.

This is line 2.

This is line 3.

### 关键代码

``````*****
for (int i = 1; i <= m; i++)
{
printf("This is line %d.n", i);
}
*****``````

## 二、高斯求和

2
1 100
10 1000

5050

500455

### 关键代码

``````*****
int sum = 0;
for (int i = a; i <= b; i++)
{
sum += i;
}
*****
int ans = (b - a + 1) * (a + b) / 2;
*****``````

## 三、星号阵列-20

2
2 3
5 4

***1

***2

123

****1

****2

****3

****4

****5

1234

### 关键代码

``````*****
for (int i = 1; i <= a + 1; i++)
{
for (int j = 1; j <= b + 1; j++)
{
if (j == b + 1 && i <= a)
cout << i;
else if (i == a + 1 && j <= b)
cout << j;
else if (i <= a && j <= b)
cout << "*";
}
cout << endl;
}
*****``````

## 四、区域范围内数字个数

2
3 -5 5
10 -5 1
3 -5 5
1 2 3

1

0

### 关键代码

``````*****
sort(num, num + m);
int cnt = 0;
for (int i = 0; i < m; i++)
{
if (num[i] >= a && num[i] <= b)
cnt++;
if (num[i] > b)
break;
}
cout << m - cnt << endl;
*****
for (int i = 1; i <= m; i++)
{
int x;
cin >> x;
if (x<a || x>b)
cnt++;
}
*****``````

## 五、孔融让梨

2
1 2 3 4 5 6 7
5 5 5 5 5 5 5

20

25

### 关键代码

``````*****
for (int i = 0; i < 7; i++)
{
cin >> a[i];
sum += a[i];
}
sort(a, a + 7);
cout << sum - a[0] - a[6] << endl;
*****``````

THE END