Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, re, sys
- from urllib.request import Request, urlopen
- # https://sangnd.wordpress.com/2014/01/03/python-chuyen-tieng-viet-co-dau-thanh-khong-dau/
- patterns = {
- '[àáảãạăắằẵặẳâầấậẫẩ]': 'a',
- '[đ]': 'd',
- '[èéẻẽẹêềếểễệ]': 'e',
- '[ìíỉĩị]': 'i',
- '[òóỏõọôồốổỗộơờớởỡợ]': 'o',
- '[ùúủũụưừứửữự]': 'u',
- '[ỳýỷỹỵ]': 'y'
- }
- def convert(text):
- output = text
- for regex, replace in patterns.items():
- output = re.sub(regex, replace, output)
- # deal with upper case
- output = re.sub(regex.upper(), replace.upper(), output)
- return output
- # ----------------------------------------------------------------------------------------
- user_id = input()
- rival_id = input()
- user_url = Request("https://oj.vnoi.info/api/v2/user/"+user_id, headers={'User-Agent': 'Mozilla/5.0'})
- user_json = json.loads(urlopen(user_url).read())
- user_list = user_json['data']['object']['solved_problems']
- rival_url = Request("https://oj.vnoi.info/api/v2/user/"+rival_id, headers={'User-Agent': 'Mozilla/5.0'})
- rival_json = json.loads(urlopen(rival_url).read().decode())
- rival_list = rival_json['data']['object']['solved_problems']
- tags = dict()
- for prob in user_list:
- prob_url = Request("https://oj.vnoi.info/api/v2/problem/"+prob, headers={'User-Agent': 'Mozilla/5.0'})
- prob_json = json.loads(urlopen(prob_url).read())
- prob_tags = prob_json['data']['object']['types']
- for tag in prob_tags:
- if tag in tags:
- tags[tag][0] += 1
- else:
- tags[tag] = [1, 0]
- for prob in rival_list:
- prob_url = Request("https://oj.vnoi.info/api/v2/problem/"+prob, headers={'User-Agent': 'Mozilla/5.0'})
- prob_json = json.loads(urlopen(prob_url).read())
- prob_tags = prob_json['data']['object']['types']
- for tag in prob_tags:
- if tag in tags:
- tags[tag][1] += 1
- else:
- tags[tag] = [0, 1]
- print('Bai doi thu da lam nhung ban thi chua:')
- for prob in user_list:
- if (prob in rival_list):
- rival_list.remove(prob)
- for prob in rival_list:
- print(prob)
- print()
- print('So bai ban va doi thu da lam theo dang:')
- for tag in tags:
- print(convert(tag),':',tags[tag])
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement