Skip to content

Instantly share code, notes, and snippets.

@77web

77web/subway.md Secret

Created June 10, 2022 11:43
Show Gist options
  • Save 77web/e6dbfa787d64fbdc8b7a32e2ad3320d3 to your computer and use it in GitHub Desktop.
Save 77web/e6dbfa787d64fbdc8b7a32e2ad3320d3 to your computer and use it in GitHub Desktop.

某N市の地下鉄の料金は1区,2区,3区,...のように駅間の距離ポイントによって決まります。
【料金表】

距離 料金
1 210
2 240
3 270
4 300

たとえばある路線に A駅 - 1 - B駅 - 2 - C駅 のように駅が並んでいるとき、A駅からB駅は1区料金、B駅からC駅は2区料金、A駅からC駅は1+2=3区料金となります。

路線の距離ポイント定義をもとに、指定された出発駅から到着駅までの料金を求めるプログラムを書いてください。
路線の駅間の距離ポイントは A,1,B,2,C のように定義し、距離ポイント定義と出発駅と到着駅の間は | で区切られています。

テストデータ

<?php
return [
    ['A,1,B,2,C|A|B', 210],
    ['A,1,B,2,C|A|C', 270],
    ['W,1,X,1,Y,2,Z|W|X', 210],
    ['W,1,X,1,Y,2,Z|W|Y', 240],
    ['W,1,X,1,Y,2,Z|Z|X', 270],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment