Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global !p
- def complete(t, opts):
- if t:
- opts = [opt[len(t):] for opt in opts if opt.startswith(t)]
- if len(opts) == 1:
- return opts[0]
- if len(opts) == 0:
- return ""
- return "(" + "|".join(opts) + ")"
- simple_var_types = sorted(["int", "long long", "string", "float", "double", "bool", "char"])
- pair_var_types = sorted(["pair<int, int>", "pair<long, long>"])
- var_types = simple_var_types + pair_var_types
- import re
- def read_cin(var_type, names):
- if t:
- opts = [opt for opt in var_types if opt.startswith(var_type)]
- if len(opts) == 1 and opts[0] in simple_var_types + pair_var_types:
- var_type = opts[0]
- result = "cin"
- for name in re.split("\s*,\s*", names):
- if var_type in simple_var_types:
- result += " >> {}".format(name)
- if var_type in pair_var_types:
- result += " >> {}.first >> {}.second".format(name, name)
- return result + ";"
- return "cin >> ;"
- endglobal
- snippet read "read values from stdin" b
- ${1:i}`!p snip.rv = complete(t[1], var_types)` ${2:n};
- `!p snip.rv = read_cin(t[1], t[2])`
- $0
- endsnippet
- snippet readvl "read vector from stdin" b
- vector<${1:i}`!p snip.rv = complete(t[1], var_types)`> ${2:v}(${3:n});
- for (int i = 0; i < $3; i++) {
- `!p snip.rv = read_cin(t[1], t[2] + "[i]")`
- }
- $0
- endsnippet
Advertisement
Add Comment
Please, Sign In to add comment