| 
 | 
 
 
发表于 2022-12-3 14:28:31
|
显示全部楼层
 
 
 
C++- #include <iostream>
 
 - #include <utility>
 
 - #include <vector>
 
 - #include <iomanip>
 
  
- /*
 
 - (1) 起重(首重)1公斤按起重资费计算(不足1公斤,按1公斤计算),超过首重的重量,按公斤(不足1公斤,按1公斤计算)收取续重费;
 
 - (2) 同城起重资费10元,续重3元/公斤;
 
 - (3) 寄往1区(江浙两省)的邮件,起重资费10元,续重4元;
 
 - (4) 寄往其他地区的邮件,起重资费统一为15元。而续重部分,不同区域价格不同:
 
 -                 2区的续重5元/公斤,
 
 -                 3区的续重6.5元/公斤,
 
 -                 4区的续重10元/公斤。
 
 - */
 
  
- using std::vector, std::pair;
 
 - vector <pair <float, float>> price{ {10, 3}, {10, 4}, {15, 5}, {15, 6.5}, {15, 10} };
 
  
- float total(int area, float weight) {
 
 -         float res = 0;
 
 -         auto [a, b] = price[area];
 
 -         res += a;
 
 -         weight -= 1;
 
 -         while (weight > 0)
 
 -         {
 
 -                 res += b;
 
 -                 weight -= 1;
 
 -         }
 
 -         return res;
 
 - }
 
  
- using std::cout, std::cin, std::endl;
 
 - using std::fixed, std::setprecision;
 
 - int main(void) {
 
 -         int area;
 
 -         float weight;
 
 -         char c;
 
 -         cin >> area >> c >> weight;
 
 -         if ((area < 0) or (area > 4)) {
 
 -                 cout << "Error in Area" << endl << "Price: 0.00" << endl;
 
 -         }
 
 -         else {
 
 -                 cout
 
 -                         << fixed << setprecision(2)
 
 -                         << "Price: "
 
 -                         << total(area, weight)
 
 -                         << endl;
 
 -         }
 
 -         return 0;
 
 - }
 
  复制代码 |   
 
 
 
 |