原价报考微软认证考试,涨价前得最后机会!!!!!!!…

自2011年7月1日起,微软认证考试费用将全面上调。即刻报名,享受现有优惠价格,只需499元即可获得四合一大礼包。报名还有机会赢取微软限量版T恤,并免费获取正版Windows7等官方软件。

从2011年7月1日起,微软认证考试价格将全球调涨。你还在犹豫吗?现在就注册,获得最优惠的价格,以499元抢购四合一大礼包,注册就有惊喜,赢取微软限量T-Shirt,还能获取正版Windows7等官方软件。

http://www.microsoft.com/china/learning/technetcampaign/

### 商店折扣问题 #### 题目描述 小明去商店买东西,商店有两种促销方案。方案一是满减优惠,满`x`元减`y`元;方案二是直接打`n`折。已知商品总价为`p`元,求小明最少需要支付的金额,结果保留两位小数。 #### 代码实现 ```cpp #include <iostream> #include <iomanip> int main() { int x, y, n, p; std::cin >> x >> y >> n >> p; double price_after_discount = p * (n / 10.0); double price_after_full_discount = p; if (p >= x) { price_after_full_discount = p - y; } double min_price = (price_after_full_discount < price_after_discount) ? price_after_full_discount : price_after_discount; std::cout << std::fixed << std::setprecision(2) << min_price << std::endl; return 0; } ``` #### 代码解释 代码首先读取四个整数`x`、`y`、`n`、`p`。然后计算方案二打折后的价格,将商品总价`p`乘以`n/10.0`得到`price_after_discount`。对于方案一,若商品总价`p`大于等于`x`,则满减后的价格为`p - y`,否则为原价`p`。最后比较两种方案的价格,取较小值作为最少支付金额,并使用`std::fixed`和`std::setprecision(2)`保留两位小数输出[^2]。 ### 最长连续段问题(C++四级真题,供参考理解知识) #### 题目描述 给定`n`个整数(可能无序、可能有重复),找出排序后最长的“相邻差为 1”的段的长度。 #### 代码实现 ```cpp #include <iostream> #include <vector> #include <algorithm> int main() { int n; std::cin >> n; std::vector<long long> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } if (n == 0) { std::cout << 0 << '\n'; return 0; } std::sort(a.begin(), a.end()); long long last = a[0]; int cnt = 1; int ans = 1; for (int i = 1; i < n; ++i) { if (a[i] == last) { continue; } else if (a[i] == last + 1) { ++cnt; } else { cnt = 1; } last = a[i]; if (cnt > ans) { ans = cnt; } } std::cout << ans << '\n'; return 0; } ``` #### 代码解释 代码先读取整数`n`和`n`个整数存于向量`a`中。若`n`为 0,直接输出 0。接着对向量`a`进行排序,初始化`last`为第一个元素,`cnt`和`ans`为 1。遍历向量,若当元素与`last`相同则跳过;若比`last`大 1,`cnt`加 1;否则`cnt`重置为 1。每次更新`last`,并更新最大连续段长度`ans`,最后输出`ans`[^3]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值