Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@gummie

# 競技プログラミング練習記 No.11【ABC146練習】

ABC146を解きました。
3完です。

D問題はこちら→

A 1min - 1ms
B 3min - 1ms
C 28min 二分探索 1ms

## A - Can't Wait for Holiday

```    string s;
cin >> s;

unordered_map<string, int> ans;
ans["SUN"] = 7;
ans["MON"] = 6;
ans["TUE"] = 5;
ans["WED"] = 4;
ans["THU"] = 3;
ans["FRI"] = 2;
ans["SAT"] = 1;

cout << ans[s];
```

`unordered_map`はハッシュテーブルのことですね。
ちなみに`map`は平衡二分探索木になります。
どっちにしても解けるのには変わりないです。

## B - ROT N

```    int n;
string s;
cin >> n >> s;

for(auto& c : s)
{
char ch = (((c + n) - 'A') % 26 + 'A');
cout << ch;
}
```

`char`は内部では文字コードを数値として持っているので、それを利用しました。
`A~Z``a~z``0~9`あたりは連番になっていてよく使います。

## C - Buy an Integer

```ll a, b, x;

ll calc(ll n)
{
ll ret = a * n;

ll log10 = 1;
while(n /= 10, n > 0)
{
log10++;
}

return ret + b * log10;
}

void solve()
{
cin >> a >> b >> x;

ll le = 0, re = x / a;
while(re - le > 1)
{
ll mid = (le + re) / 2;
if ( x < calc(mid) ) re = mid;
else le = mid;
}

cout << min(le, 1000000000LL);
}
```

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away