C12-5.5单元测评(一)
原题链接:38471.note12025-05-05 19:12:44
发布于:江苏
一、作业回顾
H1.统计车票
#include<iostream>
using namespace std;
int main(){
int n;
double x,y, a = 0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>x>>y;
a += x*y;
}
printf("%.2lf",a);
return 0;
}
H2.糖果
关键在于找到最小值和次最小值。
二、补充知识点
1. 内存单位
注意最小单位(bit)和常用单位(Byte)的进制区别
bit (比特位, 二进制位, 位, binary)最小单位
1 Byte = 8 bit
Byte (字节)常用单位
KB
MB
1 GB = 1024 MB
1 TB = 1024 GB
2. sizeof
sizeof可以计算数据类型在内存中的大小空间, 单位是Byte
cout << sizeof(char) << endl; // 1
cout << sizeof(bool) << endl; // 1
cout << sizeof(short) << endl; //2
cout << sizeof(int) << endl; //4 Byte
cout << sizeof(float) << endl; //4
cout << sizeof(long long) << endl; //8
cout << sizeof(double) << endl; //8
3. 符号整型
signed int 有符号 int
unsigned int 无符号 int
#include<iostream>
using namespace std;
int main()
{
int a[15] = {};
for (int i=1; i<=10; i++) cin >> a[i];
int maxx = 1, minx = 1;
//1、先找最大值 和最小值{下标}
for (int i=1; i<=10; i++){
if (a[i] > a[maxx]) maxx = i;
if (a[i] < a[minx]) minx = i;
}
int miny = 1;
//2、 找次最小值
for (int i=1; i<=10; i++){
if (i == minx) continue;
if (a[i] < a[miny]) miny = i;
}
//3、按照题目要求进行操作
a[minx] += a[maxx]/2;
a[miny] += a[maxx]/2;
a[maxx] = 0;
//4、输出
for (int i=1; i<=10; i++)
cout << a[i] <<' ';
return 0;
}
这里空空如也
有帮助,赞一个