第二次尝试 手建表
#include <cstdio>
using namespace std;
int main()
{
int A, B; // Code, No.s,
scanf("%d%d", &A, &B);
double pricemap[6] = {0, 4.00, 4.50, 5.00, 2.00, 1.50};
printf("Total: R$ %.2f\n", pricemap[A] * B);
return 0;
}
使用Hashmap
#include <cstdio>
#include <unordered_map>
using namespace std;
int main(){
int A, B; // Code, No.s,
scanf("%d%d", &A, &B);
unordered_map<int, double> myMap={{1, 4.00},{2, 4.50},{3, 5.00},{4, 2.00},{5, 1.50}}; // 建一个hash表
printf("Total: R$ %.2f\n", myMap[A] * B);
}