重庆大学oj系统——习题

一、question1

1.问题说明 2-9对应九宫格数字键盘的字母

2.输入23

3.输出

ad
bd
cd
ae
be
ce
af
bf
cf

4.完整代码

if __name__ == "__main__":
    import itertools
    dic = {2:['a', 'b', 'c'],
           3:['d', 'e', 'f'],
           4: ['g', 'h', 'i'],
           5: ['j', 'k', 'l'],
           6: ['m', 'n', 'o'],
           7: ['p', 'q', 'r', 's'],
           8: ['t', 'u', 'v'],
           9: ['w', 'x', 'y', 'z']
           }
    data = input()
    data_list = []
    for i in range(len(data)):
        data_list.append(dic.get(int(data[len(data)-1-i])))
    result = itertools.product(*data_list)
    for ele in result:
        print(''.join(ele)[::-1])

二、question2

1.给句子中的每个单词逆序

2.输入

第一行代码输入的句子数目

2
i love you
it's me

3.输出

i evol uoy
s'ti em

 

4.完整代码

if __name__ == "__main__":
    while True:
        n = int(input())
        sentences = []
        for i in range(n):
            sentences.append(input())
        new_senttences = []
        for sent in sentences:
            new_sent = []
            for idx, word in enumerate(sent.split(' ')):
                anti_word = word[::-1]
                new_sent.append(anti_word)
            new_senttences.append(' '.join(new_sent))
        for new_sent in new_senttences:
            print(new_sent.strip())

三、question3

1.问题描述。旋转矩阵

2.输入

第一行输入的数字表示方阵大小

3
1 2 3
4 5 6
7 8 9

3.输出

[[[7,4,1],
[8,5,2],
[9,6,3]]

4.完整代码

if __name__ == "__main__":

    while(1):
        i = 0
        a = int(input())
        b = []
        for i in range(a):
            ii = input()
            b.append([k for k in ii.split()])
        b = list(zip(*b))
        i_list = [-1 * k for k in range(1, a + 1)]
        b = [[b[col][e] for e in i_list] for col in range(a)]
        print('[', end='')
        for idx, row in enumerate(b):
            if idx != len(b)-1:
                print('['+','.join([ele for ele in row])+'],', end='')
            else:
                print('['+','.join([ele for ele in row])+']', end='')
        print(']', end='')

 

你可能感兴趣的:(重庆大学oj系统——习题)