1. 程式人生 > >hackerrank初級篇之Compare the Triplets

hackerrank初級篇之Compare the Triplets

題目說明:


大意就是:三局比賽,贏一局得1分,平局都不得分,最後分別顯示得分情況。

示例程式碼:

// compareTriplets.cpp: 定義控制檯應用程式的入口點。
//

#include "stdafx.h"
#include <windows.h>
#include <vector>
#include <iostream>
using namespace std;


vector<int> solve( int a1, int a2, int a3, int b1, int b2, int b3 )
{
    vector<int> points(2);
    int a[3] = { a1, a2, a3 };
    int b[3] = { b1, b2, b3 };

    for( int i = 0; i < 3; i++ )
    {
        if( a[i] > b[i] )
        {
            points[0]++;
        }
        else if( a[i] < b[i] )
        {
            points[1]++;
        }
    }

    return points;
}
int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int b1, b2, b3;
    cin >> b1 >> b2 >> b3;
    vector<int> result = solve( a1, a2, a3, b1, b2, b3 );

    for( int i = 0; i < result.size(); i++ )
    {
        cout << result[i] << endl;
    }

    system( "pause" );
    return 0;
}