其他分享
首页 > 其他分享> > PAT-1065 A+B and C (64bit)

PAT-1065 A+B and C (64bit)

作者:互联网

1065 A+B and C (64bit)

part 1, 1.1

自己解法(未全对)

#include <iostream>
using namespace std;

int main()
{
    long long A, B, C;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> A >> B >> C;
        cout << "Case #" << i << ": ";
        long long sum = A + B;
        if (A > 0 && B > 0 && sum < 0)
            cout << "true" << endl;
        else if (A < 0 && B < 0 && sum >= 0)
            cout << "false" << endl;
        else
        {
            if (sum > C)
                cout << "true" << endl;
            else
                cout << "false" << endl;
        }
    }
    system("pause");
    return 0;
}

大神解法

#include <cstdio>
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        long long a, b, c;
        scanf("%lld %lld %lld", &a, &b, &c);
        long long sum = a + b;
        if(a > 0 && b > 0 && sum < 0) {
            printf("Case #%d: true\n", i + 1);
        } else if(a < 0 && b < 0 && sum >= 0){
            printf("Case #%d: false\n", i + 1);
        } else if(sum > c) {
            printf("Case #%d: true\n", i + 1);
        } else {
            printf("Case #%d: false\n", i + 1);
        }
    }
    return 0;
}

总结

标签:PAT,int,64bit,scanf,1065,long,#%,&&,sum
来源: https://blog.csdn.net/seven_colors/article/details/122803022