練習問題/解答例/転置行列/Python
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[練習問題]]
#!/usr/bin/python
# -*- coding: utf-8 -*-
arr = []
while 1:
try:
arr.append(raw_input().split())
except EOFError:
break
#print('\n'.join(' '.join(e) for e in arr))
transposed = zip(*arr)
print('\n'.join(' '.join(e) for e in transposed))
#初心者用
# coding:utf-8
n = int(raw_input( "行列の行の数を入力してください: " ))
m = int(raw_input( "行列の列の数を入力してください: "))
a = [[] for x in range( n )]
b = [[] for x in range( m )]
for i in range( 1,n + 1 ):
for h in range( 1, m + 1 ):
a[ i - 1 ].append( raw_input( str( i ) + "行目の" + st...
for h in range( 1,m + 1 ):
for i in range( 1, n + 1 ):
b[ h - 1 ].append( 0 )
for d in range( n ):
print a[ d ]
for w in range( n ):
for k in range( m ):
b[ k ][ w ] = a[ w ][ k ]
print "入力された値の転置行列は"
for t in range( m ):
print b[ t ]
終了行:
[[練習問題]]
#!/usr/bin/python
# -*- coding: utf-8 -*-
arr = []
while 1:
try:
arr.append(raw_input().split())
except EOFError:
break
#print('\n'.join(' '.join(e) for e in arr))
transposed = zip(*arr)
print('\n'.join(' '.join(e) for e in transposed))
#初心者用
# coding:utf-8
n = int(raw_input( "行列の行の数を入力してください: " ))
m = int(raw_input( "行列の列の数を入力してください: "))
a = [[] for x in range( n )]
b = [[] for x in range( m )]
for i in range( 1,n + 1 ):
for h in range( 1, m + 1 ):
a[ i - 1 ].append( raw_input( str( i ) + "行目の" + st...
for h in range( 1,m + 1 ):
for i in range( 1, n + 1 ):
b[ h - 1 ].append( 0 )
for d in range( n ):
print a[ d ]
for w in range( n ):
for k in range( m ):
b[ k ][ w ] = a[ w ][ k ]
print "入力された値の転置行列は"
for t in range( m ):
print b[ t ]
ページ名: