0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaラーニング問題集「値の計算」を解いてみた

Posted at

▼考え方

問題文にある抵抗値の計算法則に沿って、回路全体の抵抗値を計算します。

▼コード

########## 処理0(準備) モジュールインポート,インプット,リストや変数定義 ###########

# math: 小数点以下の処理のためのモジュール
import math

N = int(input())

# sw: keyが抵抗のアルファベット、valueが抵抗値を示す辞書
sw = dict(input().split() for _ in range(N))
sw = {k:int(v) for k,v in sw.items()}

M = int(input())

t = list(input().split(" "))

# total: 回路全体の抵抗値を格納する変数
total = 0

# tmp: 抵抗値の計算をするための変数
tmp = 0

########## 処理1 回路全体の抵抗値を計算する処理 ###########

for i in range(M):

    # tc: 入力された抵抗の文字数を格納する変数
    tc = len(t[i])
    
    if tc == 1:
        total += sw[t[i]]
        
    else:
        for j in range(tc):
            tmp += 1/sw[t[i][j]]
        total += 1/tmp
        tmp = 0

print(math.floor(total))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?