実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
3 桁の正整数 N が与えられます。 N を十進法で表したとき、すべての桁の数字が同じであるかどうかを判定してください。
制約
- 100 \leq N \leq 999
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N を十進法で表したとき、すべての桁の数字が同じであるならば Yes を、同じでないならば No を 1 行で出力せよ。
入力例 1
444
出力例 1
Yes
444 の各桁の数字は 4,4,4 で同じなので Yes を出力してください。
入力例 2
160
出力例 2
No
160 の各桁の数字は 1,6,0 で同じではないので、No を出力してください。
入力例 3
999
出力例 3
Yes
Score : 100 points
Problem Statement
You are given a 3-digit positive integer N. Determine whether all digits are the same when N is represented in decimal.
Constraints
- 100 \leq N \leq 999
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
If all digits are the same when N is represented in decimal, output Yes in one line; otherwise, output No.
Sample Input 1
444
Sample Output 1
Yes
The digits of 444 are 4,4,4, which are the same, so output Yes.
Sample Input 2
160
Sample Output 2
No
The digits of 160 are 1,6,0, which are not the same, so output No.
Sample Input 3
999
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
ある人物の名前 S が与えられます。S の先頭の文字は英大文字であり、先頭以外の文字は英小文字です。
この人物の侍女の名前は、S の頭文字を英小文字に直し、先頭に Of をつけて得られる文字列です。この侍女の名前を答えてください。
制約
- S は長さ 1 以上 10 以下の文字列
- S の先頭の文字は英大文字
- S の先頭以外の文字は英小文字
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを 1 行に出力せよ。
入力例 1
Glen
出力例 1
Ofglen
Glen の頭文字を英小文字に直すと glen となり、さらに先頭に Of をつけると Ofglen となります。
入力例 2
I
出力例 2
Ofi
入力例 3
Fred
出力例 3
Offred
Score : 100 points
Problem Statement
You are given the name S of a certain person. The first character of S is an uppercase English letter, and the other characters are lowercase English letters.
The name of this person's handmaid is the string obtained by converting the first letter of S to lowercase and adding Of to the beginning. Find the name of this handmaid.
Constraints
- S is a string of length between 1 and 10, inclusive.
- The first character of S is an uppercase English letter.
- The characters of S other than the first are lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Output the answer on one line.
Sample Input 1
Glen
Sample Output 1
Ofglen
Converting the first letter of Glen to lowercase gives glen, and adding Of to the beginning gives Ofglen.
Sample Input 2
I
Sample Output 2
Ofi
Sample Input 3
Fred
Sample Output 3
Offred
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
数直線の原点に高橋君がいます。高橋君は座標 X にあるゴールに移動しようとしています。
座標 Y には壁があり、最初、高橋君は壁を超えて移動することができません。
座標 Z にあるハンマーを拾った後でなら、壁を破壊して通過できるようになります。
高橋君がゴールに到達することが可能か判定し、可能であれば移動距離の最小値を求めてください。
制約
- -1000 \leq X,Y,Z \leq 1000
- X,Y,Z は相異なり、いずれも 0 でない
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
X Y Z
出力
高橋君がゴールに到達することが可能であれば、移動距離の最小値を出力せよ。不可能であれば、かわりに -1 と出力せよ。
入力例 1
10 -10 1
出力例 1
10
高橋君はまっすぐゴールに向かうことができます。
入力例 2
20 10 -10
出力例 2
40
ゴールは壁の向こう側にあります。まずハンマーを拾い、壁を壊すことでゴールに到達することができます。
入力例 3
100 1 1000
出力例 3
-1
Score : 200 points
Problem Statement
Takahashi is at the origin of a number line. He wants to reach a goal at coordinate X.
There is a wall at coordinate Y, which Takahashi cannot go beyond at first.
However, after picking up a hammer at coordinate Z, he can destroy that wall and pass through.
Determine whether Takahashi can reach the goal. If he can, find the minimum total distance he needs to travel to do so.
Constraints
- -1000 \leq X,Y,Z \leq 1000
- X, Y, and Z are distinct, and none of them is 0.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
X Y Z
Output
If Takahashi can reach the goal, print the minimum total distance he needs to travel to do so. If he cannot, print -1 instead.
Sample Input 1
10 -10 1
Sample Output 1
10
Takahashi can go straight to the goal.
Sample Input 2
20 10 -10
Sample Output 2
40
The goal is beyond the wall. He can get there by first picking up the hammer and then destroying the wall.
Sample Input 3
100 1 1000
Sample Output 3
-1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋くんは回転寿司で N 皿の料理を食べました。 i 皿目の色は文字列 C_i で表されます。
また、料理の価格は皿の色と対応し、 i=1,\ldots,M のそれぞれについて、色が文字列 D_i の皿の料理は一皿 P_i 円です。また、D_1,\ldots,D_M のいずれとも異なる色の皿の料理は一皿 P_0 円です。
高橋くんが食べた料理の価格の合計を求めてください。
制約
- 1\leq N,M\leq 100
- C_i,D_i は英小文字からなる長さ 1 以上 20 以下の文字列
- D_1,\ldots,D_M はすべて異なる
- 1\leq P_i\leq 10000
- N,M,P_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N M C_1 \ldots C_N D_1 \ldots D_M P_0 P_1 \ldots P_M
出力
答えを整数として出力せよ。
入力例 1
3 2 red green blue blue red 800 1600 2800
出力例 1
5200
blue の皿は P_1 = 1600 円、red の皿は P_2 = 2800 円、green の皿は P_0 = 800 円です。
高橋くんが食べた料理の価格の合計は、2800+800+1600=5200 円です。
入力例 2
3 2 code queen atcoder king queen 10 1 1
出力例 2
21
Score : 200 points
Problem Statement
Takahashi ate N plates of sushi at a sushi restaurant. The color of the i-th plate is represented by a string C_i.
The price of a sushi corresponds to the color of the plate. For each i=1,\ldots,M, the sushi on a plate whose color is represented by a string D_i is worth P_i yen a plate (yen is the currency of Japan). If the color does not coincide with any of D_1,\ldots, and D_M, it is worth P_0 yen a plate.
Find the total amount of the prices of sushi that Takahashi ate.
Constraints
- 1\leq N,M\leq 100
- C_i and D_i are strings of length between 1 and 20, inclusive, consisting of lowercase English letters.
- D_1,\ldots, and D_M are distinct.
- 1\leq P_i\leq 10000
- N, M, and P_i are integers.
Input
The input is given from Standard Input in the following format:
N M C_1 \ldots C_N D_1 \ldots D_M P_0 P_1 \ldots P_M
Output
Print the answer as an integer.
Sample Input 1
3 2 red green blue blue red 800 1600 2800
Sample Output 1
5200
A blue plate, red plate, and green plate are worth P_1 = 1600, P_2 = 2800, and P_0 = 800 yen, respectively.
The total amount of the prices of the sushi that he ate is 2800+800+1600=5200 yen.
Sample Input 2
3 2 code queen atcoder king queen 10 1 1
Sample Output 2
21
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
文字列 S に対して操作を Q 回行います。 i 回目 (1\leq i\leq Q) の操作は文字の組 (c _ i,d _ i) で表され、次のような操作に対応します。
- S に含まれる文字 c _ i をすべて文字 d _ i で置き換える。
すべての操作が終わったあとの文字列 S を出力してください。
制約
- 1\leq N\leq2\times10^5
- S は英小文字からなる長さ N の文字列
- 1\leq Q\leq2\times10^5
- c _ i,d _ i は英小文字 (1\leq i\leq Q)
- N,Q は整数
入力
入力は以下の形式で標準入力から与えられる。
N S Q c _ 1 d _ 1 c _ 2 d _ 2 \vdots c _ Q d _ Q
出力
すべての操作が終わったあとの S を出力せよ。
入力例 1
7 atcoder 4 r a t e d v a r
出力例 1
recover
S は atcoder → atcodea → aecodea → aecovea → recover と変化します。
たとえば、4 番目の操作では S={}aecovea に含まれる a (1 文字目と 7 文字目)をすべて r に置き換えるので S={}recover となります。
すべての操作が終わったときには S={}recover となっているため、recover を出力してください。
入力例 2
3 abc 4 a a s k n n z b
出力例 2
abc
c _ i=d _ i であるような操作や S に c _ i が含まれないような操作もあります。
入力例 3
34 supercalifragilisticexpialidocious 20 g c l g g m c m r o s e a a o f f s e t t l d v p k v h x i h n n j i r s i u a
出力例 3
laklimamriiamrmrllrmlrkramrjimrial
Score: 350 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
You will perform an operation Q times on the string S. The i-th operation (1\leq i\leq Q) is represented by a pair of characters (c _ i,d _ i), which corresponds to the following operation:
- Replace all occurrences of the character c _ i in S with the character d _ i.
Print the string S after all operations are completed.
Constraints
- 1\leq N\leq2\times10^5
- S is a string of length N consisting of lowercase English letters.
- 1\leq Q\leq2\times10^5
- c _ i and d _ i are lowercase English letters (1\leq i\leq Q).
- N and Q are integers.
Input
The input is given from Standard Input in the following format:
N S Q c _ 1 d _ 1 c _ 2 d _ 2 \vdots c _ Q d _ Q
Output
Print the string S after all operations are completed.
Sample Input 1
7 atcoder 4 r a t e d v a r
Sample Output 1
recover
S changes as follows: atcoder → atcodea → aecodea → aecovea → recover.
For example, in the fourth operation, all occurrences of a in S={}aecovea (the first and seventh characters) are replaced with r, resulting in S={}recover.
After all operations are completed, S={}recover, so print recover.
Sample Input 2
3 abc 4 a a s k n n z b
Sample Output 2
abc
There may be operations where c _ i=d _ i or S does not contain c _ i.
Sample Input 3
34 supercalifragilisticexpialidocious 20 g c l g g m c m r o s e a a o f f s e t t l d v p k v h x i h n n j i r s i u a
Sample Output 3
laklimamriiamrmrllrmlrkramrjimrial