Thứ Tư, 27 tháng 4, 2022

ROLLING C++

#include <iostream>
#include <math.h>

using namespace std;

int n, t;
int a = 1, b = 2, c = 3;

void nhap(){
    scanf("%d", &n);
}

int di(){
    t = a; a = b; b = 7-t;
    return 7-a;
}

void queo(){
    t = b; b = c; c = 7-t;
}

void xuly(){
    int s = 6;
    int sv = 0;
    int z = n%2;
    while (n > 1){
        for (int i = 1; i <= 3; i ++){
            for (int j = 1; j <= n-1; j++) s += di();
            queo();
        }
        for (int i = 1; i <= n-2; i++) s += di();
        queo(); s += di();
        n = n - 2;
    }
    if (z == 0){
        cout << s - (7-a) << endl;
    } else cout << s << endl;
}

int main(){
    freopen("ROLLING.INP", "r", stdin);
    freopen("ROLLING.OUT", "w", stdout);
    nhap();
    xuly();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.