Language: C++

//algorithms.cpp
//Sun Jun  3 10:16:42 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;


//最大公倍数、最大公約数（ユークリッド互除法）
long long gcd (long long a, long long b){ //最大公約数
	if (b == 0){
		return a;
	}
	return gcd(b, a%b);
}

long long lcm (long long a, long long b){ //最小公倍数
	long long temp = gcd(a,b);
	return (a/temp)*b;
}


//深さ優先探索
bool visit[50];
bool graph[50][50];

void dfs(int v){
	visit[v] = true;
	for (int i=0;i<n;i++){
		if (visit[i] == true){
			continue;
		}else if (graph[v][i] == false){
			continue;
		}
		//do something here
		dfs(i);
	}
}


//幅優先探索 (ant37.cpp)
//次行ける場所をqueueに入れ、入れた順に処理する
	queue<int> xx;
	queue<int> yy;
	while (xx.size()){
		int x = xx.front(); xx.pop();
		int y = yy.front(); yy.pop();
		cout << x << " " << y << endl;
		for (int i=0;i<4;i++){
			if (x+dx[i] >= 0 && x+dx[i] <= n-1 && y+dy[i] >= 0 && y+dy[i] <= m-1 && a[x+dx[i]][y+dy[i]] != '#' && visited[x+dx[i]][y+dy[i]] == -1){
				xx.push(x+dx[i]);
				yy.push(y+dy[i]);
				visited[x+dx[i]][y+dy[i]] = visited[x][y]+1;
			}
		}
	}


//素因数分解
//N以下の全ての数の素因数を得る。
	for (int i=2;i<=n;i++){
		int a = 2;
		int temp = i;
		while (i>=a*a){ //iの素因数分解ここから
			if (temp%a == 0){
				num[a]++;
				temp = temp/a;
				if (a > maxa){
					maxa = a;
				}
			}else {
				a++;
			}
		}
		if (temp > maxa){
			maxa = temp;
		}
		num[temp]++; //最後の割り算の余りの処理を忘れない
	}


//全組み合わせの列挙 (next_permutation)
	int n = 3;
	int a[n];
	for (int i=0;i<n;i++){
		a[i] = i;
	}

	do {
		for (int i=0;i<n;i++){
			cout << a[i] << " ";
		}
		printf("\n");
	} while (next_permutation(a,a+n));
//0 1 2
//0 2 1 
//1 0 2 
//1 2 0 
//2 0 1 
//2 1 0 
//do whileにすること。whileのみにすると、最初の組みが試せない。


//ヒープ構造(priority_queue)
//配列を小さい順、あるいは大きい順に取り出せるデータ構造。
	int n;
	cin >> n;

	priority_queue<int> pq1; //大きい順
	priority_queue<int, vector<int>, greater<int>> pq2; //小さい順 

	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
		pq1.push(a[i]);
		pq2.push(a[i]);
	}

	while (pq1.size()){
		cout << pq1.top() << " ";
		pq1.pop();
	}
	printf ("\n");

	while (pq2.size()){
		cout << pq2.top() << " ";
		pq2.pop();
	}
	printf ("\n");



//アルファベットの数値化
char c = 'b';
int x = (int) c - 'a'; // x = 1;
int y = 4;
char z = (char) y + '0'; // z = '4'



//Union-Find木
int par[MAX_N]; //親
int treerank[MAX_N]; //木の深さ

//n要素で初期化
void init(int n){
	for (int i=0;i<n;i++){
		par[i] = i;
		treerank[i] = 0;
	}
}

//木の根（親）を見つける
int find (int x){
	if (par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合の併合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	} 

	if (treerank[x] < treerank[y]){
		par[x] = y;
	} else {
		par[y] = x;
		if (treerank[x] == treerank[y]){
			treerank[x]++;
		}
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}


//ベルマン＝フォード法(O(|V|x|E|), ant95_vec)
struct edge {int from, to, cost;};

edge es[100];
int d[100];
int v,e;

void shortest_path(int s){
	fill(d,d+v+1,INF);
	d[s] = 0;
	while (true){
		bool update = false;
		for (int i=0;i<e;i++){
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}else if (d[e.to] != INF && d[e.from] > d[e.to] + e.cost){
				d[e.from] = d[e.to] + e.cost;
				update = true;
			}
		}
		for (int i=1;i<=v;i++){
			cout << d[i] << " ";
		}
		printf("\n");
		if (!update){
			break;
		}
	}
}

//ダイクストラ法(ant97) (O(|E|log|V|)負の辺がある場合は使用不可。) vにノード数、eに辺数を入れて使う。
struct edge {int to, cost;};

vector<edge> G[100];
int d[100];
int v,e;

void dijkstra (int s){
	priority_queue<P, vector<P>, greater<P>> pq; //小さい順 
	fill (d,d+v,INF);
	d[s] = 0;
	pq.push(P(0,s));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		int vtemp = p.second;
//		cout << p.first << " " << p.second << "     ";
		if (d[vtemp] < p.first){
//			cout << "pass" << endl;
			continue;
		}
		for (int i=0;i<G[vtemp].size();i++){
			edge e = G[vtemp][i];
			if (d[e.to] > d[vtemp] + e.cost){
				d[e.to] = d[vtemp] + e.cost;
				pq.push(P(d[e.to],e.to));
			}
		}
//		for (int i=0;i<v;i++){
//			cout << d[i] << " ";
//		}
//		printf("\n");
	}
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:33:24: error: 'n' was not declared in this scope
   33 |         for (int i=0;i<n;i++){
      |                        ^
a.cc: At global scope:
a.cc:49:9: error: expected unqualified-id before 'while'
   49 |         while (xx.size()){
      |         ^~~~~
a.cc:65:9: error: expected unqualified-id before 'for'
   65 |         for (int i=2;i<=n;i++){
      |         ^~~
a.cc:65:22: error: 'i' does not name a type
   65 |         for (int i=2;i<=n;i++){
      |                      ^
a.cc:65:27: error: 'i' does not name a type
   65 |         for (int i=2;i<=n;i++){
      |                           ^
a.cc:88:15: error: size of array 'a' is not an integral constant-expression
   88 |         int a[n];
      |               ^
a.cc:89:9: error: expected unqualified-id before 'for'
   89 |         for (int i=0;i<n;i++){
      |         ^~~
a.cc:89:22: error: 'i' does not name a type
   89 |         for (int i=0;i<n;i++){
      |                      ^
a.cc:89:26: error: 'i' does not name a type
   89 |         for (int i=0;i<n;i++){
      |                          ^
a.cc:93:9: error: expected unqualified-id before 'do'
   93 |         do {
      |         ^~
a.cc:98:11: error: expected unqualified-id before 'while'
   98 |         } while (next_permutation(a,a+n));
      |           ^~~~~
a.cc:110:13: error: redefinition of 'int n'
  110 |         int n;
      |             ^
a.cc:87:13: note: 'int n' previously defined here
   87 |         int n = 3;
      |             ^
a.cc:111:9: error: 'cin' does not name a type
  111 |         cin >> n;
      |         ^~~
a.cc:116:15: error: size of array 'a' is not an integral constant-expression
  116 |         int a[n];
      |               ^
a.cc:116:13: error: redefinition of 'int a [1]'
  116 |         int a[n];
      |             ^
a.cc:88:13: note: 'int a [1]' previously declared here
   88 |         int a[n];
      |             ^
a.cc:117:9: error: expected unqualified-id before 'for'
  117 |         for (int i=0;i<n;i++){
      |         ^~~
a.cc:117:22: error: 'i' does not name a type
  117 |         for (int i=0;i<n;i++){
      |                      ^
a.cc:117:26: error: 'i' does not name a type
  117 |         for (int i=0;i<n;i++){
      |                          ^
a.cc:123:9: error: expected unqualified-id before 'while'
  123 |         while (pq1.size()){
      |         ^~~~~
a.cc:127:16: error: expected constructor, destructor, or type conversion before '(' token
  127 |         printf ("\n");
      |                ^
a.cc:129:9: error: expected unqualified-id before 'while'
  129 |         while (pq2.size()){
      |         ^~~~~
a.cc:133:16: error: expected constructor, destructor, or type conversion before '(' token
  133 |         printf ("\n");
      |                ^
a.cc:146:9: error: 'MAX_N' was not declared in this scope
  146 | int par[MAX_N]; //親
      |         ^~~~~
a.cc:147:14: error: 'MAX_N' was not declared in this scope
  147 | int treerank[MAX_N]; //木の深さ
      |              ^~~~~
a.cc: In function 'void init(int)':
a.cc:152:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  152 |                 par[i] = i;
      |                 ^~~
      |                 __pstl::execution::v1::par
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from a.cc:9:
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:153:17: error: 'treerank' was not declared in this scope
  153 |                 treerank[i] = 0;
      |                 ^~~~~~~~
a.cc: In function 'int find(int)':
a.cc:159:13: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  159 |         if (par[x] == x){
      |             ^~~
      |             __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'void unite(int, int)':
a.cc:174:13: error: 'treerank' was not declared in this scope
  174 |         if (treerank[x] < treerank[y]){
      |             ^~~~~~~~
a.cc:175:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  175 |                 par[x] = y;
      |                 ^~~
      |                 __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:177:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
  177 |                 par[y] = x;
      |                 ^~~
      |                 __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'void shortest_path(int)':
a.cc:197:22: error: 'INF' was not declared in this scope
  197 |         fill(d,d+v+1,INF);
      |                      ^~~
a.cc: At global scope:
a.cc:222:8: error: redefinition of 'struct edge'
  222 | struct edge {int to, cost;};
      |        ^~~~
a.cc:190:8: note: previous definition of 'struct edge'
  190 | struct edge {int from, to, cost;};
      |        ^~~~
a.cc:225:5: error: redefinition of 'int d [100]'
  225 | int d[100];
      |     ^
a.cc:193:5: note: 'int d [100]' previously declared here
  193 | int d[100];
      |     ^
a.cc:226:5: error: redefinition of 'int v'
  226 | int v,e;
      |     ^
a.cc:194:5: note: 'int v' previously declared here
  194 | int v,e;
      |     ^
a.cc:226:7: error: redefinition of 'int e'
  226 | int v,e;
      |       ^
a.cc:194:7: note: 'int e' previously declared here
  194 | int v,e;
      |       ^
a.cc: In function 'void dijkstra(int)':
a.cc:229:24: error: 'P' was not declared in this scope
  229 |         priority_queue<P, vector<P>, greater<P>> pq; //小さい順
      |                        ^
a.cc:229:35: error: template argument 2 is invalid
  229 |         priority_queue<P, vector<P>, greater<P>> pq; //小さい順
      |                                   ^
a.cc:229:47: error: template argument 1 is invalid
  229 |         priority_queue<P, vector<P>, greater<P>> pq; //小さい順
      |                                               ^~
a.cc:229:47: error: template argument 2 is invalid
a.cc:229:47: error: template argument 3 is invalid
a.cc:230:21: error: 'INF' was not declared in this scope
  230 |         fill (d,d+v,INF);
      |                     ^~~
a.cc:232:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
  232 |         pq.push(P(0,s));
      |            ^~~~
a.cc:233:19: error: request for member 'empty' in 'pq', which is of non-class type 'int'
  233 |         while(!pq.empty()){
      |                   ^~~~~
a.cc:234:18: error: expected ';' before 'p'
  234 |                 P p = pq.top();
      |                  ^~
      |                  ;
a.cc:235:20: error: request for member 'pop' in 'pq', which is of non-class type 'int'
  235 |                 pq.pop();
      |                    ^~~
a.cc:236:29: error: 'p' was not declared in this scope; did you mean 'pq'?
  236 |                 int vtemp = p.second;
      |                             ^
      |                             pq
a.cc:246:36: error: request for member 'push' in 'pq', which is of non-class type 'int'
  246 |                                 pq.push(P(d[e.to],e.to));
      |                                    ^~~~