Untitled

unknown
plain_text
15 days ago
1.4 kB
3
Indexable
Never
```#include <bits/stdc++.h>
#define endl '\n'
#define maxn 105
#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 100000000000007

using namespace std;
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"};
int n,pos,res,ans,k;
string s;
int Findcan(string x)
{
For(i,0,9)
if(x == can[i])
return i;
return -1;
}
int Findchi(string x)
{
For(i,0,11)
if(x == chi[i])
return i;
return -1;
}
void inp()
{
cin >> n >> s;
}
void solve()
{
if(Findcan(s) != -1)
{
pos = Findcan(s);
res = n % 10;
int pre = n - res + pos;
int nex = n + (pos - res + 10) % 10;
if(abs(n - pre) <= abs(n - nex)) ans = pre; else ans = nex;
}
else
{
pos = Findchi(s);
res = n % 12;
int pre = n - res + pos;
int nex = n + (pos - res + 12) % 12;
if(abs(n - pre) <= abs(n - nex)) ans = pre; else ans = nex;
}
cout << ans;
}
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