2017年9月5日 星期二

[Python]高中生程式解題系統

  1. #a003. 兩光法師占卜術
  2. import sys
  3. for line in sys.stdin:
  4. a,b = line.split()
  5. result = (int(a*2) + int(b))%3
  6. if result== 0 :
  7. print('普通')
  8. elif result== 1 :
  9. print('吉')
  10. else :
  11. print('大吉')
  12. #a004. 文文的求婚
  13. import sys
  14. for year in sys.stdin:
  15. if int(year)%4 == 0 and int(year)%100 != 0 :
  16. print('閏年')
  17. elif int(year)%400 == 0 :
  18. print('閏年')
  19. else :
  20. print('平年')
  21. #a005. Eva 的回家作業
  22. import sys
  23. for input in sys.stdin:
  24. if len(input.split()) > 3 :
  25. a,b,c,d = input.split()
  26. if int(a)*int(d) == int(b)*int(c) :
  27. print('%s %s %s %s %d' % (a,b,c,d,int(d)/int(c)*int(d)))
  28. else :
  29. print('%s %s %s %s %d' % (a,b,c,d,int(d)-int(c)+int(d)))
  30. #a009. 解碼器
  31. import sys
  32. output = ''
  33. for input in sys.stdin:
  34. for char in input:
  35. if not char.isspace() :
  36. newchar = chr(int(ord(char))-7)
  37. output += newchar
  38. else :
  39. output += '\n'
  40. print(output)
  41. #a020: 身分證檢驗
  42. import sys
  43. output = ''
  44. city = [10,11,12,13,14,15,16,17,34,18,19,20,21,22,35,23,24,25,26,27,28,29,32,30,31,33]
  45. i = 0
  46. for input in sys.stdin:
  47. for char in input:
  48. if not char.isspace() :
  49. idx = ord(char)-ord('A')
  50. else :
  51. break
  52. i+=1
  53. if i >0 :
  54. break
  55. newStr = str(city[idx]) + input
  56. newStr = newStr[:2] + newStr[3:]
  57. verify = int(newStr[0]) + int(newStr[10])
  58. for i in range(1,10,1):
  59. verify += int(newStr[i])*int(10-i)
  60. if verify%10 == 0:
  61. print('real')
  62. else:
  63. print('fake')
  64. #a034: 二進位制轉換
  65. import sys
  66. for input in sys.stdin:
  67. output = bin(int(input))
  68. output = output[2:]
  69. print(output)
  1. #a040: 平面圓形切割
  1. import sys
  2. for line in sys.stdin:
  3. n = int(line)
  4. print(n*n -n +2)
  5. #a044: 空間切割
  6. while True:
  7. try:
  8. plane = int(input().strip('\r').strip('\n'))
  9. block = 2**plane
  10. print("{0}".format(block))
  11. except:
  12. break
  13. #a104: 排序
  14. import sys
  15. for sortNum in sys.stdin:
  16. output = ''
  17. output2 = ''
  18. if len(sortNum.split()) > 1:
  19. output = sorted(sortNum.split())
  20. i = 0
  21. for a in output:
  22. if i==0:
  23. output2 += a
  24. else :
  25. output2 += ' ' + a
  26. i +=1
  27. print(output2)
  28. while 1:
  29. try:
  30. input()
  31. list1 = input().strip('\r').split(' ')
  32. list2 = [int(x) for x in list1]
  33. list2.sort()
  34. for y in list2:
  35. print(y,end=' ')
  36. print()
  37. except EOFError:
  38. break
  39. #a147: Print it all
  40. import sys
  41. for lim in sys.stdin:
  42. output = ''
  43. if int(lim) > 0:
  44. i = 0
  45. for a in range(1,int(lim),1):
  46. if i==0:
  47. output += str(a)
  48. elif a%7 != 0:
  49. output += ' ' + str(a)
  50. i +=1
  51. print(output)
  52. #a149: 乘乘樂
  53. while True:
  54. try:
  55. size = int(input().strip('\r').strip('\n'))
  56. for item in range(0, size , 1):
  57. numStr = input()
  58. list2 = [int(x) for x in numStr]
  59. num = 1
  60. for y in list2:
  61. num *= y
  62. print(num)
  63. #print("hello, {0}".format(line))
  64. except:
  65. break
  66. #a038: 數字翻轉
  67. while True:
  68. try:
  69. list1 = input().strip('\r').strip('\n')
  70. list2 = [int(x) for x in list1]
  71. list2.reverse()
  72. x = ''
  73. for y in list2:
  74. x += str(y)
  75. print(int(x))
  76. except EOFError:
  77. break
  78. #a022: 迴文
  79. while True:
  80. try:
  81. x=input().strip('\r').strip('\n')
  82. list1 = list(x)
  83. list1.reverse()
  84. if list(x)==list1:
  85. print('yes')
  86. else:
  87. print('no')
  88. except EOFError:
  89. break
  90. #a148: You Cannot Pass?!
  91. while True:
  92. try:
  93. score=input().strip('\r').strip('\n').split(' ')
  94. i = 0
  95. item = 0
  96. sumScore = 0
  97. for x in score:
  98. if i==0:
  99. item = int(x)
  100. else:
  101. sumScore += int(x)
  102. i+=1
  103. if sumScore/item>59:
  104. result = 'no'
  105. else:
  106. result = 'yes'
  107. print(result)
  108. except EOFError:
  109. break
  110. #a738: 最大公约数
  111. def is_number(s):
  112. try:
  113. float(s)
  114. return True
  115. except ValueError:
  116. pass
  117. try:
  118. import unicodedata
  119. unicodedata.numeric(s)
  120. return True
  121. except (TypeError, ValueError):
  122. pass
  123. return False
  124. while True:
  125. try:
  126. list1 = input().strip('\r').split(' ')
  127. if len(list1) > 1 and is_number(list1[0].strip()) and is_number(list1[1].strip()):
  128. list2 = [int(x) for x in list1]
  129. list2.sort()
  130. a = int(list2[0])
  131. if a!=0 :
  132. b = int(list2[1])
  133. while b != 0:
  134. t = a % b;
  135. a = b
  136. b = t
  137. print(a)
  138. except EOFError:
  139. break
  140. #a799: 正值國
  141. while True:
  142. output = 0
  143. try:
  144. x = input().strip('\r')
  145. if int(x) < 0:
  146. output = -int(x)
  147. else:
  148. output = int(x)
  149. print(output)
  150. except EOFError:
  151. break
  152. #a065: 提款卡密碼
  153. while True:
  154. output = ''
  155. try:
  156. x = input().strip('\r')
  157. x2 = list(x)
  158. y = [ord(x3) for x3 in x2]
  159. for i in range(0, len(y)-1):
  160. output += str(abs(y[i+1]-y[i]))
  161. print(output)
  162. except EOFError:
  163. break
  164. #d050: 妳那裡現在幾點了?
  165. while True:
  166. try:
  167. x = int(input().strip('\r'))
  168. if x>=15:
  169. print(x-15)
  170. else:
  171. print(x+24-15)
  172. except EOFError:
  173. break
  174. #d051: 糟糕,我發燒了!
  175. while True:
  176. try:
  177. f = int(input().strip('\r'))
  178. c = (f-32)*5/9
  179. c = "%.3f" % c
  180. print(c)
  181. except EOFError:
  182. break
  183. #d058: BASIC 的 SGN 函數
  184. while True:
  185. try:
  186. x = int(input().strip('\r'))
  187. if x > 0:
  188. print(1)
  189. elif x == 0:
  190. print(0)
  191. else:
  192. print(-1)
  193. except EOFError:
  194. break
  195. #d060: 還要等多久啊?
  196. while True:
  197. try:
  198. x = int(input().strip('\r'))
  199. if 25 >= x:
  200. print(25-x)
  201. else:
  202. print(25+60-x)
  203. except EOFError:
  204. break
  205. #d063: 0 與 1
  206. while True:
  207. try:
  208. x = int(input().strip('\r'))
  209. print(int(x==0))
  210. except EOFError:
  211. break
  212. #d064: 奇數?
  213. while True:
  214. try:
  215. x = int(input().strip('\r'))
  216. if x%2==0:
  217. print('Even')
  218. else:
  219. print('Odd')
  220. except EOFError:
  221. break
  222. #d065: 三人行必有我師
  223. while True:
  224. try:
  225. list1 = input().strip('\r').split(' ')
  226. list2 = [int(x) for x in list1]
  227. print(max(list2))
  228. except EOFError:
  229. break
  230. #d066: 上學去吧!
  231. from datetime import datetime as dt
  232. while True:
  233. try:
  234. x = input().strip('\r')
  235. test = dt.strptime(x, "%H %M")
  236. s = dt.strptime("07 30", "%H %M")
  237. e = dt.strptime("17 00", "%H %M")
  238. if s <= test and test < e:
  239. print('At School')
  240. else:
  241. print('Off School')
  242. except EOFError:
  243. break
  244. #d068: 該減肥了!
  245. while True:
  246. try:
  247. x = int(input())
  248. w = 0
  249. if x > 50:
  250. w = int(x)-1
  251. else:
  252. w = x
  253. print(w)
  254. except EOFError:
  255. break
  256. #d074: 電腦教室
  257. while True:
  258. try:
  259. x = input().strip('\r')
  260. list1 = input().strip('\r').split(' ')
  261. list2 = [int(x) for x in list1]
  262. print(max(list2))
  263. except EOFError:
  264. break
  265. #a263: 日期差幾天
  266. import datetime
  267. while True:
  268. try:
  269. list_day1 = input().strip('\r').split(' ')
  270. day1 = datetime.date(int(list_day1[0]),int(list_day1[1]),int(list_day1[2]))
  271. #設定要相減的日期
  272. list_day2 = input().strip('\r').split(' ')
  273. day2 = datetime.date(int(list_day2[0]),int(list_day2[1]),int(list_day2[2]))
  274. result = abs(day1 - day2)
  275. print (str(result.days))
  276. except EOFError:
  277. break
  278. #d124: 3的倍数
  279. while True:
  280. try:
  281. i = input()
  282. if int(i) % 3 == 0:
  283. print('yes')
  284. else:
  285. print('no')
  286. except EOFError:
  287. break
  288. #d069: 文文的求婚--續集 (n 行版)
  289. while True:
  290. try:
  291. num = int(input())
  292. for i in range(0,num,1):
  293. year = input().strip('\r')
  294. if int(year)%4 == 0 and int(year)%100 != 0 :
  295. print('a leap year')
  296. elif int(year)%400 == 0 :
  297. print('a leap year')
  298. else:
  299. print('a normal year')
  300. except EOFError:
  301. break
  302. #d070: 文文的求婚--續集 (0 尾版)
  303. while True:
  304. try:
  305. year = int(input().strip('\r'))
  306. if year != 0:
  307. if int(year)%4 == 0 and int(year)%100 != 0 :
  308. print('a leap year')
  309. elif int(year)%400 == 0 :
  310. print('a leap year')
  311. else:
  312. print('a normal year')
  313. else:
  314. break
  315. except EOFError:
  316. break
  317. #d071: 文文的求婚--續集 (EOF 版)
  318. while True:
  319. try:
  320. year = int(input().strip('\r'))
  321. if int(year)%4 == 0 and int(year)%100 != 0 :
  322. print('a leap year')
  323. elif int(year)%400 == 0 :
  324. print('a leap year')
  325. else:
  326. print('a normal year')
  327. except EOFError:
  328. break
  329. #d072: 文文的求婚--續集 (Case 版)
  330. while True:
  331. try:
  332. num = int(input())
  333. for i in range(1,num+1,1):
  334. year = input().strip('\r')
  335. if int(year)%4 == 0 and int(year)%100 != 0 :
  336. print('Case '+i+': a leap year')
  337. elif int(year)%400 == 0 :
  338. print('Case '+i+': a leap year')
  339. else:
  340. print('Case '+i+': a normal year')
  341. except EOFError:
  342. break
  343. #d073: 分組報告
  344. while True:
  345. try:
  346. team = 0
  347. num = int(input())
  348. if num % 3 == 0:
  349. team = int(num/3)
  350. else:
  351. team=int(num/3)+1
  352. print(team)
  353. except EOFError:
  354. break
  355. #d086: 態度之重要的證明
  356. while True:
  357. try:
  358. inputStr = input().strip('\r').strip().lower()
  359. if inputStr != '0':
  360. inputList = list(inputStr)
  361. output = 0
  362. output2 = ''
  363. for score in inputList:
  364. if ord(score)-96<=26 and ord(score)-96>=1:
  365. output += ord(score)-96
  366. else:
  367. output2 = 'Fail'
  368. if output2.strip()!='':
  369. print(output2)
  370. else:
  371. print(output)
  372. except EOFError:
  373. break
  374. #d827: 買鉛筆
  375. while True:
  376. try:
  377. inputStr = input().strip('\r').strip()
  378. all = int(inputStr)
  379. output = divmod(all, 12)
  380. print(output[0] * 50 + output[1] * 5)
  381. except EOFError:
  382. break
  383. #d483: hello, world
  384. while True:
  385. try:
  386. inputStr = input().strip('\r').strip()
  387. print(hello, world)
  388. except EOFError:
  389. break
  390. #a058: MOD3
  391. while True:
  392. try:
  393. b = 0
  394. c = 0
  395. d = 0
  396. inputSize = int(input().strip('\r'))
  397. for i in range(0,inputSize,1):
  398. a=int(input().strip('\r'))
  399. if a%3==0:
  400. b += 1
  401. elif a%3==1:
  402. c += 1
  403. else:
  404. d += 1
  405. print('%d %d %d' % (b, c, d))
  406. except EOFError:
  407. break
  408. #a053: Sagit's 計分程式
  409. while True:
  410. try:
  411. score = 0
  412. inputSrt = int(input().strip('\r'))
  413. if inputSrt >= 0 and inputSrt <= 10:
  414. score = 6 * inputSrt
  415. elif inputSrt>10 and inputSrt<=20:
  416. score= 60 + 2*(inputSrt-10)
  417. elif inputSrt>20 and inputSrt<=39:
  418. score= 80 + 1*(inputSrt-20)
  419. else:
  420. score= 100
  421. print(score)
  422. except EOFError:
  423. break
  424. #d460: 山六九之旅
  425. while True:
  426. try:
  427. year = int(input().strip('\r'))
  428. cost = 0
  429. if year < 6:
  430. cost = 0
  431. elif year>=6 and year<12: cost="590" elif="" year="">=12 and year<18: cost="790" elif="" year="">=18 and year<60: break="" cost="" else:="" eoferror:="" except="" pre="" print="">