PAT basic1021-1025(Python版)
2014-11-09 14:58
323 查看
Python2环境:
1021:
1022:
1023:
1024:
1025:
有一个case内存超限,还有一个没过,Python在时间效率和空间效率上还有待改进啊。。也没心情跳最后一个没过的case了。
1021:
from sys import exit str = raw_input() digit = [] for i in str: digit.append(i) for i in range(10): if digit.count('%d' % i) > 0: print '%d:%d' % (i, digit.count('%d' % i)) exit(0)
1022:
from sys import exit str = raw_input().split() num = int(str[0]) + int(str[1]) d = int(str[2]) list = [] out = '' if num == 0: out = '0' while num != 0: list.append(num % d) num /= d list.reverse() for i in list: out += '%d' % i print out exit(0)
1023:
from sys import exit str = raw_input().split() num = [int(str[i]) for i in range(len(str))] out = '' flag = 0 for i in range(1, len(num)+1): if num[i] != 0: flag = i break out += '%d' % flag for i in range(len(num)): if i == flag: out += ('%s' % i) * (num[i]-1) else: out += ('%s' % i) * num[i] print out exit(0)
1024:
from sys import exit str = raw_input().split('E') if str[1] != '': index = int(str[1]) else: index = 0 num = str[0] intPart = num.split('.')[0] xsPart = num.split('.')[1] out = '' if num[0] == '-': out += '-' if index == 0: out = str[0] elif index > 0: out += '%d' % int(abs(int(intPart))) if len(xsPart) <= index: out += xsPart out += '0' * (index - len(xsPart)) else: out += xsPart[:index] out += '.' out += xsPart[index:] else: out += '0.' out += '0' * (abs(index)-1) out += '%d' % int(abs(int(intPart))) out += xsPart print out exit(0)
1025:
#!/usr/bin/python from sys import exit str = raw_input().split() dict = {} ListLen = int(str[1]) revsLen = int(str[2]) list = [] for i in range(ListLen): tmp = raw_input().split() dict[tmp[0]] = tmp[1:] cur = str[0] for i in range(ListLen): list.append([cur, dict[cur][0], dict[cur][1]]) cur = dict[cur][1] count = 0 revList = [] while ListLen - count >= revsLen: y=list[count:count+revsLen] y.reverse() count += revsLen revList.extend(y) revList.extend(list[count:]) cur = revList[0][0] count = 0 while ListLen - count >= revsLen: for i in range(revsLen-1): revList[count+i][2] = revList[count+i+1][0] if count + revsLen < ListLen: revList[count+revsLen-1][2] = revList[count+revsLen][0] count += revsLen revList[-1][2] = '-1' for i in range(ListLen): print revList[i][0], revList[i][1], revList[i][2] exit(0)
有一个case内存超限,还有一个没过,Python在时间效率和空间效率上还有待改进啊。。也没心情跳最后一个没过的case了。
相关文章推荐
- PAT (Basic) 1021~1025
- PAT Basic Level 1021. 个位数统计 (15)
- 【C++】PAT(basic level)1025. 反转链表 (25)
- PAT (Basic Level) Practise (中文)- 1021. 个位数统计 (15)
- PAT (Basic Level)1025. 反转链表
- PAT (Basic Level)1021. 个位数统计
- Pat(Basic Level)Practice--1021(个位数统计)
- PAT (Basic Level) Practise-1021
- PAT (Basic Level) Practise:1021. 个位数统计
- PAT basic1016-1020(Python版)
- PAT_Basic 1021
- 浙大 pat Basic Level 1025
- PAT1025 BASIC:反转链表 (25)
- PAT1021 BASIC:个位数统计 (15)
- PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)
- PAT basic 1027(Python版)
- 浙大 pat Basic Level 1021
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15)
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15) C语言
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15)