Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.5 kB
6
Indexable
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 1005
#define TASK bai1
#define For(i,a,b) for ( int i = a; i <= b; i++ )
#define Ford(i,a,b) for ( int i = a; i >= b; i-- )
#define MOD 10000000

using namespace std;

int n;
string s;
string Can[10] = { "CANH", "TAN" ,"NHAM", "QUY", "GIAP" , "AT" , "BINH" , "DINH", "MAU", "KY" } ;
string Chi[12] = { "THAN", "DAU", "TUAT", "HOI", "TI", "SUU", "DAN", "MAO", "THIN", "TY", "NGO", "MUI"} ;

void inp() {
    cin >> n >> s ;
}

bool Find(string a) {
    For(i,0,9)
        if ( a == Can[i] ) return 0 ;
    For(i,0,11)
        if ( a == Chi[i] ) return 1 ;
}

void Cang() {
    int start = ( n + 1 ) % 10 ;
    int stop ;
    For(i,0,9)
        if ( Can[i] == s ) {
            stop = i+1;
            break ;
        }
    int kc = min(abs(start - stop), 10 - abs(start - stop)) ;
    if ( Can[(n-kc)%10] == s ) cout << n - kc ;
        else cout << n + kc ;
}

void Chig() {
    int start = ( n + 1 ) % 12 ;
    int stop ;
    For(i,0,11)
        if ( Chi[i] == s ) {
            stop = i + 1;
            break ;
        }
    int kc = min(abs(start - stop), 12 - abs(start - stop)) ;
    if  ( Chi[(n-kc)%12] == s ) cout << n - kc ;
        else cout << n + kc ;
}

void solve() {
    int loai = Find(s) ;
    if ( loai == 0 ) Cang() ;
        else Chig() ;
}

int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);
    if(fopen("bai1.inp","r")){
        freopen("bai1.inp","r",stdin);
    }
    inp();
    solve();
}
Leave a Comment