11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】競プロ用テンプレート(VS Codeユーザースニペット機能)

Last updated at Posted at 2022-08-15

競プロのコンテストに参加するときに使っているPythonのテンプレート(スニペット)です

小文字大文字など好みがあると思うので、使いやすいように修正して使ってください

VS Codeのユーザースニペット機能

こちらの記事で丁寧に説明されています

スニペットファイル

最新のスニペットファイルはGithubにあります
Gitリポジトリはこちら

[2023/01/15]時点のスニペットファイル
python.code-snippets
{
	"n=in": {
		"prefix": "n=",
		"body": "n=int(input())",
	},
	"k=in": {
		"prefix": "k=",
		"body": "k=int(input())",
	},
	"m=in": {
		"prefix": "m=",
		"body": "m=int(input())",
	},
	"s=": {
		"prefix": "s=",
		"body": "s=input()",
	},
	"n,m=": {
		"prefix": "n,m=",
		"body": "n,m=map(int,input().split())",
	},
	"h,w=": {
		"prefix": "h,w=",
		"body": "h,w=map(int,input().split())",
	},
	"a=li": {
		"prefix": "a=li",
		"body": "a=list(map(int,input().split()))",
	},
	"int(input())": {
		"prefix": "ii",
		"body": "int(input())",
	},
	"for": {
		"prefix": "fo",
		"body": "for i in range(n)",
	},
	"for k": {
		"prefix": "fok",
		"body": "for k in range(n):",
	},
	"for m": {
		"prefix": "fom",
		"body": "for k in range(m):",
	},
	"for _": {
		"prefix": "fo_",
		"body": "for _ in range(n):",
	},
	"map": {
		"prefix": "ma",
		"body": "map(int,input().split())",
	},
	"map-1": {
		"prefix": "mala",
		"body": "map(lambda x:int(x)-1,input().split())",
	},
	"list": {
		"prefix": "li",
		"body": "list(map(int,input().split()))",
	},
	"i-1": {
		"prefix": "la",
		"body": "lambda x:int(x)-1",
	},
	"defaultdict": {
		"prefix": "di=",
		"body": "from collections import defaultdict\ndi=defaultdict()",
	},
	"sys.set": {
		"prefix": "sys",
		"body": "import sys\nsys.setrecursionlimit(10**6)",
	},
	"uf":{
		"prefix": "uf",
		"body": "from collections import defaultdict\nclass UnionFind():\n\tdef __init__(self, n):\n\t\tself.n = n\n\t\tself.parents = [-1] * n\n\n\tdef find(self, x):\n\t\tif self.parents[x] < 0:\n\t\t\treturn x\n\t\telse:\n\t\t\tself.parents[x] = self.find(self.parents[x])\n\t\t\treturn self.parents[x]\n\n\tdef union(self, x, y):\n\t\tx = self.find(x)\n\t\ty = self.find(y)\n\n\t\tif x == y:\n\t\t\treturn\n\n\t\tif self.parents[x] > self.parents[y]:\n\t\t\tx, y = y, x\n\n\t\tself.parents[x] += self.parents[y]\n\t\tself.parents[y] = x\n\n\tdef size(self, x):\n\t\treturn -self.parents[self.find(x)]\n\n\tdef same(self, x, y):\n\t\treturn self.find(x) == self.find(y)\n\n\tdef members(self, x):\n\t\troot = self.find(x)\n\t\treturn [i for i in range(self.n) if self.find(i) == root]\n\n\tdef roots(self):\n\t\treturn [i for i, x in enumerate(self.parents) if x < 0]\n\n\tdef group_count(self):\n\t\treturn len(self.roots())\n\n\tdef all_group_members(self):\n\t\tgroup_members = defaultdict(list)\n\t\tfor member in range(self.n):\n\t\t\tgroup_members[self.find(member)].append(member)\n\t\treturn group_members\n\nuf=UnionFind(n)",
	},
	"INF":{
		"prefix": "INF",
		"body": "INF=float('inf')",
	},
	"mod":{
		"prefix": "mod",
		"body": "mod=998244353",
	},
	"MOD":{
		"prefix": "MOD",
		"body": "MOD=1000000007",
	},
	"inside":{
		"prefix": "inside",
		"body": "def inside(y,x):\n\treturn 0<=y<h and 0<=x<w",
	},
	"yes":{
		"prefix": "yes",
		"body": "print('Yes')",
	},
	"no":{
		"prefix": "no",
		"body": "print('No')",
	},
	"abc":{
		"prefix": "abc",
		"body": "abc = 'abcdefghijklmnopqrstuvwxyz'",
	},
	"ABC":{
		"prefix": "ABC",
		"body": "ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'",
	},
}

終わりに

ユーザスニペット機能を利用するとコーディングが楽になります
よく使うコードはじゃんじゃんスニペットへ登録していいと思います

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?