Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int pairCount, firstNum, secondNum;
- cin >> pairCount >> firstNum >> secondNum;
- int equalValue = firstNum + secondNum;
- int maxdiff = 0;
- for (int i = 1; i < pairCount; i++) {
- cin >> firstNum >> secondNum;
- int currentValue = firstNum + secondNum;
- int currentDiff = abs(equalValue - currentValue);
- if (currentDiff > maxdiff) {
- maxdiff = currentDiff;
- }
- else {
- equalValue = currentValue;
- }
- }
- if (maxdiff == 0) {
- cout << "Yes, value=" << equalValue << endl;
- }
- else {
- cout << "No, maxdiff=" << maxdiff << endl;
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int pairCount, firstNum, secondNum;
- cin >> pairCount >> firstNum >> secondNum;
- int equalValue = firstNum + secondNum;
- int maxdiff = 0;
- for (int i = 1; i < pairCount; i++) {
- cin >> firstNum >> secondNum;
- int currentValue = firstNum + secondNum;
- int currentDiff = abs(equalValue - currentValue);
- currentDiff > maxdiff ? maxdiff = currentDiff : equalValue = currentValue;
- }
- cout << (maxdiff == 0 ? "Yes, value=" + to_string(equalValue) : "No, maxdiff=" + to_string(maxdiff)) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement