criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by sotetsuk on 2015/07/14.
 */
public class AOJ0558 implements {
    public static final int MAX_H = 1005;
    public static final int MAX_W = 1005;
    public static final int MAX_N = 15;
    public static int H, W, N;
    public static char[][] grid = new char[MAX_H][MAX_W];
    public static int[][] d = new int[MAX_H][MAX_W];
    public static Pair[] pos = new Pair[MAX_N];

    public static int[] dx = {-1, 0, 1, 0};
    public static int[] dy = {0, -1, 0, 1};

    public static class Pair {
        int first, second;
        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public static void read() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt(); W = sc.nextInt(); N = sc.nextInt();

        for(int i = 0; i < H; i++) {
            grid[i] = sc.next().toCharArray();
        }

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(grid[i][j] == 'S') {
                    pos[0] = new Pair(i, j);
                }
                if('0' <= grid[i][j] && grid[i][j] <= '9') {
                    int k = Integer.valueOf(String.valueOf(grid[i][j]));
                    pos[k] = new Pair(i, j);
                }
            }
        }
    }

    public static int bfs(Pair start, Pair goal) {
        // fill 2-d array d by -1
        for(int[] arr: d) Arrays.fill(arr, -1);
        // This deque is used as queue for bfs
        ArrayDeque<Pair> q = new ArrayDeque<Pair>();
        q.add(start);
        d[start.first][start.second] = 0;
        while(!q.isEmpty()) {
            Pair now = q.pop();
            int nowX = now.first; int nowY = now.second;
            // stopping condition
            if(nowX == goal.first && nowY == goal.second) {
                return d[nowX][nowY];
            }
            // search 4 destination
            for(int i = 0; i < 4; i++) {
                Pair next = new Pair(nowX + dx[i], nowY + dy[i]);
                int nextX = next.first; int nextY = next.second;
                if(0 <= nextX && nextX < H && 0 <= nextY && nextY < W
                        && grid[nextX][nextY] != 'X' && d[nextX][nextY] == -1) {
                    q.add(next);
                    d[nextX][nextY] = d[nowX][nowY] + 1;
                }
            }
        }

        return -1; // something is wrong
    }

    public static void main(String[] args) {
            int ans = 0;
            read();
            for(int i = 0; i < N; i++) {
                ans += bfs(pos[i], pos[i + 1]);
            }
            System.out.println(ans);
    }

}

Compiler output:
Main.java:8: error: illegal start of type
public class AOJ0558 implements {
                                ^
1 error
Language: Java

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by sotetsuk on 2015/07/14.
 */
public class Main implements {
    public static final int MAX_H = 1005;
    public static final int MAX_W = 1005;
    public static final int MAX_N = 15;
    public static int H, W, N;
    public static char[][] grid = new char[MAX_H][MAX_W];
    public static int[][] d = new int[MAX_H][MAX_W];
    public static Pair[] pos = new Pair[MAX_N];

    public static int[] dx = {-1, 0, 1, 0};
    public static int[] dy = {0, -1, 0, 1};

    public static class Pair {
        int first, second;
        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public static void read() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt(); W = sc.nextInt(); N = sc.nextInt();

        for(int i = 0; i < H; i++) {
            grid[i] = sc.next().toCharArray();
        }

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(grid[i][j] == 'S') {
                    pos[0] = new Pair(i, j);
                }
                if('0' <= grid[i][j] && grid[i][j] <= '9') {
                    int k = Integer.valueOf(String.valueOf(grid[i][j]));
                    pos[k] = new Pair(i, j);
                }
            }
        }
    }

    public static int bfs(Pair start, Pair goal) {
        // fill 2-d array d by -1
        for(int[] arr: d) Arrays.fill(arr, -1);
        // This deque is used as queue for bfs
        ArrayDeque<Pair> q = new ArrayDeque<Pair>();
        q.add(start);
        d[start.first][start.second] = 0;
        while(!q.isEmpty()) {
            Pair now = q.pop();
            int nowX = now.first; int nowY = now.second;
            // stopping condition
            if(nowX == goal.first && nowY == goal.second) {
                return d[nowX][nowY];
            }
            // search 4 destination
            for(int i = 0; i < 4; i++) {
                Pair next = new Pair(nowX + dx[i], nowY + dy[i]);
                int nextX = next.first; int nextY = next.second;
                if(0 <= nextX && nextX < H && 0 <= nextY && nextY < W
                        && grid[nextX][nextY] != 'X' && d[nextX][nextY] == -1) {
                    q.add(next);
                    d[nextX][nextY] = d[nowX][nowY] + 1;
                }
            }
        }

        return -1; // something is wrong
    }

    public static void main(String[] args) {
            int ans = 0;
            read();
            for(int i = 0; i < N; i++) {
                ans += bfs(pos[i], pos[i + 1]);
            }
            System.out.println(ans);
    }

}

Compiler output:
Main.java:8: error: illegal start of type
public class Main implements {
                             ^
1 error
Language: Java

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by sotetsuk on 2015/07/14.
 */
public class AOJ0558 {
    public static final int MAX_H = 1005;
    public static final int MAX_W = 1005;
    public static final int MAX_N = 15;
    public static int H, W, N;
    public static char[][] grid = new char[MAX_H][MAX_W];
    public static int[][] d = new int[MAX_H][MAX_W];
    public static Pair[] pos = new Pair[MAX_N];

    public static int[] dx = {-1, 0, 1, 0};
    public static int[] dy = {0, -1, 0, 1};

    public static class Pair {
        int first, second;
        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public static void read() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt(); W = sc.nextInt(); N = sc.nextInt();

        for(int i = 0; i < H; i++) {
            grid[i] = sc.next().toCharArray();
        }

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(grid[i][j] == 'S') {
                    pos[0] = new Pair(i, j);
                }
                if('0' <= grid[i][j] && grid[i][j] <= '9') {
                    int k = Integer.valueOf(String.valueOf(grid[i][j]));
                    pos[k] = new Pair(i, j);
                }
            }
        }
    }

    public static int bfs(Pair start, Pair goal) {
        // fill 2-d array d by -1
        for(int[] arr: d) Arrays.fill(arr, -1);
        // This deque is used as queue for bfs
        ArrayDeque<Pair> q = new ArrayDeque<Pair>();
        q.add(start);
        d[start.first][start.second] = 0;
        while(!q.isEmpty()) {
            Pair now = q.pop();
            int nowX = now.first; int nowY = now.second;
            // stopping condition
            if(nowX == goal.first && nowY == goal.second) {
                return d[nowX][nowY];
            }
            // search 4 destination
            for(int i = 0; i < 4; i++) {
                Pair next = new Pair(nowX + dx[i], nowY + dy[i]);
                int nextX = next.first; int nextY = next.second;
                if(0 <= nextX && nextX < H && 0 <= nextY && nextY < W
                        && grid[nextX][nextY] != 'X' && d[nextX][nextY] == -1) {
                    q.add(next);
                    d[nextX][nextY] = d[nowX][nowY] + 1;
                }
            }
        }

        return -1; // something is wrong
    }

    public static void main(String[] args) {
            int ans = 0;
            read();
            for(int i = 0; i < N; i++) {
                ans += bfs(pos[i], pos[i + 1]);
            }
            System.out.println(ans);
    }

}

Compiler output:
Main.java:8: error: class AOJ0558 is public, should be declared in a file named AOJ0558.java
public class AOJ0558 {
       ^
1 error
Language: Java


import java.util.*;

public class A {

	public static class Point {
		public int x;
		public int y;
		public int pre;
		public Point(){
			
		}
		public Point(int x1,int y1) {
			x = x1;
			y = y1;
		}
		public Point(int x1,int y1 ,int pre1) {
			x = x1;
			y = y1;
			pre= pre1;
		}
		public void setX(int x1){
			x =x1;
		}
	};
	
	final static int MAXN = 1000;
	private static Point S = new Point() ,G = new Point() ;   //表示起点和?点
	private static int N,W,H;
	private static char[][] graph = new char[MAXN][MAXN];   //存?
	private static int[][] vis = new int[MAXN][MAXN];   //存距?
	private static Point[] aim = new Point[10];  //存目?坐?
	
	private static int dx[] = {1,-1,0,0},dy[]={0,0,-1,1};
	
	public static void main(String[] args) {
		
		Scanner fin = new Scanner(System.in);		
		//?入数据
		H = fin.nextInt();
		W = fin.nextInt();
		N = fin.nextInt();
		fin.nextLine();
		for(int i=0; i<H; i++){
			String line = fin.nextLine().replace(" ", "");
			for(int j=0; j<W; j++){
				graph[i][j] = line.charAt(j);
				if(graph[i][j] == 'S'){
					S.x = i;
					S.y = j;
				}
				if(graph[i][j] >= '1' && graph[i][j] <= '9'){
					int t = graph[i][j] -'0';
					aim[t] = new Point(i,j);
				}
			}
		}
		int step = 0; 
		for(int i=1; i<=N; i++){
			G.x = aim[i].x;
			G.y = aim[i].y;
			System.out.println(S.x + " " + S.y +" "+G.x + " " + G.y);
			step += bfs(S,G);
			S.x = G.x;
			S.y = G.y;
		}		
		System.out.printf("%d\n", step);

	}
	
	private static int bfs(Point S, Point G){
		Queue<Point> sq = new LinkedList<Point>();
		

		//?次遍?前，重置vis中存放的?
		for(int i=0 ;i<MAXN; i++){
			Arrays.fill(vis[i], -1);
		}
		
		sq.add(S);
		vis[S.x][S.y] = 0;
		while(!sq.isEmpty()){
			Point qh = sq.poll();		//返回?列中第一个元素，并?除一个元素						
			if(qh.x == G.x && qh.y == G.y){
				break;
			}
			for(int k =0; k<4; k++){
				//*****因??里??的是引用，所以一定要新?建qe，然后添加到?列中，其?才不会?
				Point qe = new Point(qh.x + dx[k], qh.y + dy[k]);
				
				if(check(qe.x,qe.y) == 1){
					System.out.println(" qe  "+qe.x + " "+ qe.y +" "+ vis[qe.x][qe.y]);
					sq.add(qe);   //入?					
					vis[qe.x][qe.y] = vis[qh.x][qh.y] + 1;					
				}
			}
		}
		return vis[G.x][G.y];
	}
	private static int check(int x, int y){
		int flag=1;
		if(x<0 || x>=H || y<0 || y>=W)
			flag =0;
		else if(graph[x][y] == 'X' || vis[x][y] != -1)
	    	flag =0;		
		return flag;
	}

}

Compiler output:
Main.java:4: error: class A is public, should be declared in a file named A.java
public class A {
       ^
1 error
Language: Java

package cad.week2.a2;

import java.awt.Point;
import java.util.LinkedList;
import java.util.Scanner;

import cad.week2.a.Main.P;

public  class Main{
	public static class P{
		int x;
		int y;
		public P(){
			
		}
		public P(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
	}
	
	static P s = new P();
	static P g = new P();
	static int[][] graph = new int[1000][1000];
	static int[][] vis = new int[1000][1000];
	static int[] dx = {1,0,-1,0};
	static int[] dy = {0,1,0,-1};
	static int n,w,h;
	static int step;
	static P[] aim = new P[10];
	
	public static int bfs(P s, P g){
		LinkedList<P> que = new LinkedList<>();
		
		for (int i = 0; i < 1000; i++) {
			for (int j = 0; j < 1000; j++) {
				vis[i][j] = -1;
			}
		}
		que.add(s);
		vis[s.x][s.y] = 0;
		while(!que.isEmpty()){
			P p = que.poll();
			//que.pop();
			if (p.x == g.x && p.y == g.y) {
				break;
			}
			for (int i = 0; i < 4; i++) {
				P n = new P();
				n.x = p.x + dx[i];
				n.y = p.y + dy[i];
				if(0<=n.x&&n.x<h&&0<=n.y&&n.y<w&&graph[n.x][n.y]!='X'&&vis[n.x][n.y]==-1){
		             
					   que.add(n);
		               vis[n.x][n.y] = vis[p.x][p.y]+1;
		           }
			}
		}
		return vis[g.x][g.y];
	}
	
	
	
	
	
	public static void main(String[] args) {
		Scanner fin = new Scanner(System.in);		
		//?入数据
		h = fin.nextInt();
		w = fin.nextInt();
		n = fin.nextInt();
		fin.nextLine();
		for(int i=0; i<h; i++){
			String line = fin.nextLine().replace(" ", "");
			for(int j=0; j<w; j++){
				graph[i][j] = line.charAt(j);
				if(graph[i][j] == 'S'){
					s.x = i;
					s.y = j;
				}
				if(graph[i][j] >= '1' && graph[i][j] <= '9'){
					int t = graph[i][j] -'0';
					aim[t] = new P(i,j);
				}
			}
		}
		int step = 0; 
		for(int i=1; i<=n; i++){
			g.x = aim[i].x;
			g.y = aim[i].y;
			step += bfs(s,g);
			s.x = g.x;
			s.y = g.y;
		}		
		System.out.printf("%d\n", step);
	}
}

Compiler output:
Main.java:7: error: package cad.week2.a.Main does not exist
import cad.week2.a.Main.P;
                       ^
1 error
Language: Java

import com.sun.xml.internal.xsom.impl.scd.Iterators;

import java.util.*;

public class Main {

    private static class Point {
        int x;
        int y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public boolean equals(Point p) {
            return p.x == x && p.y == y;
        }

        public String toString() {
            return "point: " + x + "," + y;
        }
    }

    private static char[][] room;
    private static LinkedList<Point> queue;
    private static int[][] directions = {{0,1}, {1,0}, {0,-1}, {-1,0}};
    private static Point[] points;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w, h, n;
        int count = 0;
        String lineOfInput;

        h = sc.nextInt();
        w = sc.nextInt();
        n = sc.nextInt();

        room = new char[h][w];
        points = new Point[n+1];

        sc.nextLine(); // for empty line
        for (int i = 0; i < h; i++) {
            lineOfInput = sc.nextLine();
            for (int j = 0; j < w; j++) {
                room[i][j] = lineOfInput.charAt(j);
                if (room[i][j] == 'S') {
                    points[0] = new Point(j, i);
                }
                if (room[i][j] != '.' && room[i][j] != 'X' && room[i][j] != 'S') {
                    points[Integer.parseInt(Character.toString(room[i][j]))] = new Point(j, i);
                }
            }
        }

//        System.out.println(Arrays.toString(points));
//        System.out.println(points[1].equals(new Point(2,2)));

        for (int i = 1; i <= n; i++) {
            count += bfs(i);
        }

        System.out.println(count);
    }

    private static int bfs(int next) {
        int count = 0;
        Point temp;
        int nx, ny;
        boolean[][] visited = new boolean[room.length][room[0].length];

        queue = new LinkedList<>();
        queue.add(points[next-1]);
        queue.add(null);
        visited[points[next-1].y][points[next-1].x] = true;
        while ((queue.peek() != null && !queue.peek().equals(points[next])) || queue.peek() == null) {
//            System.out.println(queue.peek());
            temp = queue.poll();
            if (temp == null) {
                count++;
                queue.add(null);
            }
            else {
                for (int[] direction: directions) {
                    nx = temp.x + direction[0];
                    ny = temp.y + direction[1];
                    if (nx >= 0 && ny >= 0 && nx < room[0].length && ny < room.length) {
                        if (room[ny][nx] != 'X' && !visited[ny][nx]) {
                            queue.add(new Point(nx, ny));
                            visited[ny][nx] = true;
                        }
                    }
                }
            }
        }

        return count;
    }
}

Compiler output:
Main.java:1: error: package com.sun.xml.internal.xsom.impl.scd does not exist
import com.sun.xml.internal.xsom.impl.scd.Iterators;
                                         ^
1 error
Language: Java

package nofill_nosubmit;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class AOJ_0558 
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int dx[]={1,0,-1,0};
		int dy[]={0,1,0,-1};
		while(in.hasNext())
		{
			int H=in.nextInt(),W=in.nextInt();
			int N=in.nextInt();
			int sh=0,sw=0,gh=0,gw=0;
			int ans=0,cnt=0;
			int visit[][]=new int[H][W];
			char map[][]=new char[H][W];
			LinkedList<String>que=new LinkedList<String>();
			for(int i=0;i<H;i++)
			{
				String st=in.next();
				for(int j=0;j<W;j++)
				{
					map[i][j]=st.charAt(j);
					if(map[i][j]=='S')
					{
						sh=i;
						sw=j;
					}
					else if(map[i][j]=='1')
					{
						gh=i;
						gw=j;
					}
				}
			}
			que.add(sh+" "+sw);
			while(!que.isEmpty())
			{
				int size=que.size();
				for(int i=0;i<size;i++)
				{
					String now[]=que.poll().split(" ");
					int nh=Integer.valueOf(now[0]);
					int nw=Integer.valueOf(now[1]);
					visit[nh][nw]=1;
					if(nh==gh&&nw==gw)
					{
						i=size-1;
						while(!que.isEmpty())
							que.poll();
						cnt++;
						if(cnt==N)
							break;
						else
							for(int j=0;j<H;j++)
								for(int k=0;k<W;k++)
								{
									if(cnt==1)
										if(map[j][k]=='2')
										{
											gh=j;
											gw=k;
										}
									if(cnt==2)
										if(map[j][k]=='3')
										{
											gh=j;
											gw=k;
										}
									if(cnt==3)
										if(map[j][k]=='4')
										{
											gh=j;
											gw=k;
										}
									if(cnt==4)
										if(map[j][k]=='5')
										{
											gh=j;
											gw=k;
										}
									if(cnt==5)
										if(map[j][k]=='6')
										{
											gh=j;
											gw=k;
										}
									if(cnt==6)
										if(map[j][k]=='7')
										{
											gh=j;
											gw=k;
										}
									if(cnt==7)
										if(map[j][k]=='8')
										{
											gh=j;
											gw=k;
										}
									if(cnt==8)
										if(map[j][k]=='9')
										{
											gh=j;
											gw=k;
										}
								}
						visit =new int[H][W];
					}
					for(int j=0;j<4;j++)
					{
						int h=dy[j]+nh;
						int w=dx[j]+nw;
						if(h>=0&&h<H&&w>=0&&w<W&&map[h][w]!='X'&&visit[h][w]==0)
							que.add(h+" "+w);
					}
				}
				if(cnt==N)
					break;
				ans++;
			}
			System.out.println(ans);
		}
	}
}

Compiler output:
Main.java:5: error: class AOJ_0558 is public, should be declared in a file named AOJ_0558.java
public class AOJ_0558 
       ^
1 error
Language: C

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[1001][1001];
int v[1001][1001],n,h,w,sx,sy,ans,s;
int dir[4][2]={-1,0,1,0,0,1,0,-1};
char b[1001];
int check(int x,int y)
{
    if(x>=0&&x<h&&y>=0&&y<w)
        return 1;
    return 0;
}
void dfs(int x,int y,char c,int cnt)
{
    int t1,t2;
    if(cnt>=1000)
        return;
    for(int i=0;i<4;i++)
    {
       // printf("%d\n",cnt);
        t1=x+dir[i][0];
        t2=y+dir[i][1];
        if(check(t1,t2)&&v[t1][t2]==0&&a[t1][t2]!='X')
        {

            v[t1][t2]=1;
            dfs(t1,t2,c,cnt+1);
            v[t1][t2]=0;
        }
         if(a[t1][t2]==c&&check(t1,t2))
        {
            ans=min(ans,cnt+1);
            sx=t1;
            sy=t2;
            //printf("%d, ",ans);
        }
    }

}
int main()
{
    int  i,j,k,m,l;
    while(~scanf("%d %d %d",&h,&w,&n))
    {
        s=0;
        memset(v,0,sizeof(v));
        for(i=0;i<h;i++)
        {
            scanf("%s",&a[i]);
        }
        for(i=0;i<n;i++)
        {
            b[i]=i+1+'0';
        }
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                if(a[i][j]=='S')
                {
                    sx=i;
                    sy=j;
                }
            }
        }

        //printf("%d %d\n",sx,sy);

        for(i=0;i<n;i++)
        {
            ans=100000;
            //printf("%d %d %c\n",sx,sy,b[i]);

            dfs(sx,sy,b[i],0);
            s+=ans;
        }
        printf("%d\n",s);
    }
    return 0;
}

Compiler output:
main.c:3:9: fatal error: algorithm: No such file or directory
    3 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char a[1001][1001];
int v[1001][1001],n,h,w,sx,sy,ans;
int dir[4][2]={-1,0,1,0,0,1,0,-1};
char b[1001];
int s[101][101];
struct st
{
    int x,y;
}st1,st2,fl;
queue<st>qq;
int check(st kk)
{
    int x=kk.x;
    int y=kk.y;
    if(x>=0&&x<h&&y>=0&&y<w)
        return 1;
    return 0;
}
int  bfs(char c,int cnt)
{
    memset(v,0,sizeof(v));
    memset(s,0,sizeof(s));
    while(!qq.empty())
    {
        st1=qq.front();
        qq.pop();
        if(a[st1.x][st2.y]==c)
            break;
        for(int i=0;i<4;i++)
        {
            st2.x=st1.x+dir[i][0];
            st2.y=st1.y+dir[i][1];
            if(check(st2)&&v[st2.x][st2.y]==0&&a[st2.x][st2.y]!='X')
            {
                v[st2.x][st2.y]=1;
                s[st2.x][st2.y]=s[st1.x][st1.y]+1;
                qq.push(st2);
            }
        }
    }
    return s[st1.x][st1.y];
}
int main()
{
    int  i,j,k,m,l;
    while(~scanf("%d %d %d",&h,&w,&n))
    {

        getchar();
        memset(v,0,sizeof(v));
        memset(s,0,sizeof(s));
        for(i=0;i<h;i++)
        {
            scanf("%s",&a[i]);
        }
        for(i=0;i<n;i++)
        {
            b[i]=i+1+'0';
        }
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                if(a[i][j]=='S')
                {
                    sx=i;
                    sy=j;
                }
            }
        }

        //printf("%d %d\n",sx,sy);
        fl.x=sx;
        fl.y=sy;
        int sum=0;
        for(i=0;i<n;i++)
       {
            qq.push(fl);
            sum+=bfs(b[i],0);
            printf("[%d]\n",sum);
        }
        printf("%d\n",sum);
    }
    return 0;
}

Compiler output:
main.c:3:9: fatal error: algorithm: No such file or directory
    3 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C

#include <cstdio>
#include <map>
#include <queue>
#include <string>

using namespace std;

const int INF = 100000000;
const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = 9;

int H, W, N;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W]; // ?????????????????\??´?????§??????????????°, 1~N??§?????????????????§????????°??????+1
int step[MAX_N+1]; // ?????????????????\??´?????§??????????????°, 1~N??§?????????????????§????????°??????+1
int sx, sy, gx, gy;
int power = 1; // ??????????????????
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

typedef pair<int, int> P;

void reset_d() {
  for (int i = 0; i < H; i++)
    for(int j = 0; j < W; j++) d[i][j] = INF;
}

int bfs(int sx, int sy, int c) {
  queue<P> que;
  reset_d();
  d[sx][sy] = c;
  que.push(P(sx, sy));
  while(que.size()) {
    P p = que.front(); que.pop();
    if (field[p.first][p.second] - '0' == N && step[N] != 0) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if ( 0 <= nx && nx <= H && 0 <= ny && ny <= W && field[nx][ny] != 'X' && d[nx][ny] == INF) {
        d[nx][ny] = d[p.first][p.second] + 1;
        que.push(P(nx, ny));
        if (field[nx][ny] - '0' == power) {
          step[power] = d[nx][ny];
          power++;
          return bfs(nx, ny, d[nx][ny]);
        }
      }
    }
  }
  return step[N];
}

void solve(int sx, int sy) {
  int res = bfs(sx, sy, 0);
  printf("%d\n", res);
}


int main() {
  scanf("%d %d %d", &H, &W, &N);
  for (int i = 0; i < H; i++) {
    scanf("%s", field[i]);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (field[i][j] == 'G') {
        gx = i;
        gy = j;
      }
    }
  }
  solve(sx, sy);
  return 0;
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct node
{
    int x, y, step;
};
int a, b, ans, n;
int book[1010][1010];
char on[1010][1010];
void bfs(int x, int y, int k)
{
    memset(book, 0, sizeof(book));
    int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
    node s, e;
    int f = 0;
    s.step = 0;
    s.x = x;
    s.y = y;
    book[x][y] = 1;
    queue<node>q;
    q.push(s);
    while(!q.empty())
    {
        s = q.front();
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            e.x = s.x + dir[i][0];
            e.y = s.y + dir[i][1];
            e.step = s.step+1;
            if(e.x < 0 || e.y < 0 || e.x >= a || e.y >= b || book[e.x][e.y] || on[e.x][e.y] == 'X')
                continue;
            if(on[e.x][e.y] == '0'+k)
            {
                ans += e.step;
                f = 1;
                break;
            }
            book[e.x][e.y] = 1;
            q.push(e);
        }
        if(f)
            break;
    }
    if(f && k == n)
        return;
    bfs(e.x, e.y, k+1);
}
int main ()
{
    while(~scanf("%d %d %d", &a, &b, &n))
    {
        int i, j;
        for(i = 0; i < a; i++)
            scanf("%s", on[i]);
        ans = 0;
        for(i = 0; i < a; i++)
            for(j = 0; j < b; j++)
                if(on[i][j] == 'S')
                {
                    bfs(i, j, 1);
                    break;
                }
        printf("%d\n", ans);
    }
    return 0;
}

Compiler output:
main.c:1:9: fatal error: cstdio: No such file or directory
    1 | #include<cstdio>
      |         ^~~~~~~~
compilation terminated.
Language: C

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define MAX 1001

int h, w, n;
char city[MAX][MAX];
int step[10];
int direc1[4] = { -1,0,1,0 }, direc2[4] = { 0,1,0,-1 };

void dfs(char (&nowcity)[MAX][MAX], int nowstep, bool find, int nowi, int nowj, int nowpower, map<int, int> visited) {
	if (find) {
		if (step[nowpower-1] == -1) {
			step[nowpower-1] = nowstep;
		}
		else
		{
			step[nowpower-1] = min(step[nowpower-1], nowstep);
		}
		return;
	}
	if (step[nowpower] != -1) {
		if (nowstep >= step[nowpower]) {
			return;
		}
	}
	for (int i = 0; i < 4; i++) {
		if (nowi + direc1[i] >= 0 && nowi + direc1[i] < h&&nowj + direc2[i] >= 0 && nowj + direc2[i] < w) {

			if (nowcity[nowi + direc1[i]][nowj + direc2[i]] == '.') {
				if (!visited[(nowi + direc1[i]) * w + nowj + direc2[i]]) {
					visited[(nowi + direc1[i]) * w + nowj + direc2[i]]=1;
					dfs(nowcity, nowstep + 1, false, nowi + direc1[i], nowj + direc2[i], nowpower, visited);
				}	
			}
			else if (nowcity[nowi + direc1[i]][nowj + direc2[i]] >= '0'&&nowcity[nowi + direc1[i]][nowj + direc2[i]] <= '9')
			{
				int num = nowcity[nowi + direc1[i]][nowj + direc2[i]] - '0';
				if (nowpower == num) {					
					//nowcity[nowi + direc1[i]][nowj + direc2[i]] = '.';
					/*visited.clear();
					visited[(nowi + direc1[i]) * w + nowj + direc2[i]] =1;*/
					dfs(nowcity, nowstep + 1, true, nowi + direc1[i], nowj + direc2[i], nowpower,visited);
				}
				else {
					if (!visited[(nowi + direc1[i]) * w + nowj + direc2[i]]) {
						visited[(nowi + direc1[i]) * w + nowj + direc2[i]] =1;
						dfs(nowcity, nowstep + 1, false, nowi + direc1[i], nowj + direc2[i], nowpower,visited);
					}				
				}
			}
		}
	}
}



int main() {
	cin >> h >> w >> n;
	int nowi[10], nowj[10];
	
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> city[i][j];
			if (city[i][j] == 'S') {
				nowi[0] = i;
				nowj[0] = j;
				city[i][j] = '.';
			}
			if (city[i][j] >= '0'&&city[i][j] <= '9') {
				nowi[city[i][j] - '0'] = i;
				nowj[city[i][j] - '0'] = j;
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		step[i] = -1;
	}
	map<int, int>visited;
	for (int i = 0; i < n; i++) {
		visited.clear();
		visited[nowi[i] * w + nowj[i]] = 1;
		dfs(city, 0, false, nowi[i], nowj[i], i+1, visited);
	}
	int sum=0;
	for (int i = 0; i < n; i++) {
		sum += step[i];
	}
	cout << sum << endl;
	//system("pause");
	return 0;
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define MAXN 1005
using namespace std;

struct node {
	int i;
	int j;
	char val;
};

int H, W, N;//H(1 <= H <= 1000)、W(1 <= W <=1000)、N(1 <= N <= 9)
char m[MAXN][MAXN];
queue<node> q;

bool flag = 0;
int t1 = 0;
char flag_m[MAXN][MAXN];
void search(int i, int j, char val)
{
	if (flag_m[i][j]<val) {
		if (m[i][j] == 'X')
		{
			return;
		}
		if (m[i][j] == '.' || m[i][j] != val)
		{
			q.push({ i, j, val });
			//flag_m[i][j] = true;
			t1++;
		}
		if (m[i][j] == val)
		{
			if (val ==(char)('0' + N))
			{
				flag = 1;
			}
			else
			{
				q.push({ i, j, val + 1 });
				//flag_m[i][j] = true;
				m[i][j] = '.';
				t1++;
			}
		}
	}
	return;
}
int main()
{
	int si, sj;
	scanf("%d %d %d", &H, &W, &N);
	for (int i = 1; i <= H; i++)
	{
		getchar();
		for (int j = 1; j <= W; j++)
		{
			scanf("%c", &(m[i][j]));
			if (m[i][j] == 'S')
			{
				si = i;
				sj = j;
			}
		}
	}

	//

	q.push({ si, sj, '1' });
	memset(flag_m, '0', sizeof(flag_m));
	int t = 1;
	int time = 0;

	while (!q.empty() && (!flag))
	{
		time++;
		t1 = 0;
		while (t-- && (!flag))
		{
			node n1 = q.front(); q.pop();
			si = n1.i; sj = n1.j;
			flag_m[si][sj] = n1.val;
			if (si > 1)
			{
				search(si - 1, sj, n1.val);
			}
			if (si < H)
			{
				search(si + 1, sj, n1.val);
			}
			if (sj > 1)
			{
				search(si, sj - 1, n1.val);
			}
			if (sj < W)
			{
				search(si, sj + 1, n1.val);
			}

		}
		t = t1;
	}
	printf("%d\n", time);
	return 0;
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C


import java.util.*;

public class Main {

	public static class Point {
		public int x;
		public int y;
		public int pre;
		public Point(){
			
		}
		public Point(int x1,int y1) {
			x = x1;
			y = y1;
		}
		public Point(int x1,int y1 ,int pre1) {
			x = x1;
			y = y1;
			pre= pre1;
		}
		public void setX(int x1){
			x =x1;
		}
	};
	
	final static int MAXN = 1000;
	private static Point S = new Point() ,G = new Point() ;   //表示起点和?点
	private static int N,W,H;
	private static char[][] graph = new char[MAXN][MAXN];   //存?
	private static int[][] vis = new int[MAXN][MAXN];   //存距?
	private static Point[] aim = new Point[10];  //存目?坐?
	
	private static int dx[] = {1,-1,0,0},dy[]={0,0,-1,1};
	
	public static void main(String[] args) {
		
		Scanner fin = new Scanner(System.in);		
		//?入数据
		H = fin.nextInt();
		W = fin.nextInt();
		N = fin.nextInt();
		fin.nextLine();
		for(int i=0; i<H; i++){
			String line = fin.nextLine().replace(" ", "");
			for(int j=0; j<W; j++){
				graph[i][j] = line.charAt(j);
				if(graph[i][j] == 'S'){
					S.x = i;
					S.y = j;
				}
				if(graph[i][j] >= '1' && graph[i][j] <= '9'){
					int t = graph[i][j] -'0';
					aim[t] = new Point(i,j);
				}
			}
		}
		int step = 0; 
		for(int i=1; i<=N; i++){
			G.x = aim[i].x;
			G.y = aim[i].y;
			step += bfs(S,G);
			S.x = G.x;
			S.y = G.y;
		}		
		System.out.printf("%d\n", step);

	}
	
	private static int bfs(Point S, Point G){
		Queue<Point> sq = new LinkedList<Point>();
		

		//?次遍?前，重置vis中存放的?
		for(int i=0 ;i<MAXN; i++){
			Arrays.fill(vis[i], -1);
		}
		
		sq.add(S);
		vis[S.x][S.y] = 0;
		while(!sq.isEmpty()){
			Point qh = sq.poll();		//返回?列中第一个元素，并?除一个元素						
			if(qh.x == G.x && qh.y == G.y){
				break;
			}
			for(int k =0; k<4; k++){
				//*****因??里??的是引用，所以一定要新?建qe，然后添加到?列中，其?才不会?
				Point qe = new Point(qh.x + dx[k], qh.y + dy[k]);
				
				if(check(qe.x,qe.y) == 1){					
					sq.add(qe);   //入?					
					vis[qe.x][qe.y] = vis[qh.x][qh.y] + 1;					
				}
			}
		}
		return vis[G.x][G.y];
	}
	private static int check(int x, int y){
		int flag=1;
		if(x<0 || x>=H || y<0 || y>=W)
			flag =0;
		else if(graph[x][y] == 'X' || vis[x][y] != -1)
	    	flag =0;		
		return flag;
	}

}

Compiler output:
main.c:2:1: error: unknown type name 'import'
    2 | import java.util.*;
      | ^~~~~~
main.c:2:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    2 | import java.util.*;
      |            ^
main.c:4:1: error: unknown type name 'public'
    4 | public class Main {
      | ^~~~~~
main.c:4:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Main'
    4 | public class Main {
      |              ^~~~
Language: C

#include<stdio.h>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct PP{
	int x;
	int y;
	int Z;
	int c;
};
char s[1000][1000],C[11]={"0123456789"};
int D[1000][1000];
int A[1000][1000],d;
int main(){
	PP S;
	queue<PP> P;
	int  w,h;
	int d=0,i=0,j=0,l=-1;
	int x[4]={ 1, 0,-1,0};
	int y[4]={ 0 ,1,0,-1};
	scanf("%d %d %d",&h,&w,&d);
	memset(A,0,sizeof(A));
   memset(D,0,sizeof(D));
		for(i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
		if(s[i][j]=='S'){
			S.x=j;
			S.y=i;
			S.Z=0;
			S.c=1;
			P.push(S);
		}
		}
	}
	while(1){
		l++;
		
		if(l==4) {
			l=0;
			P.pop();
		}
		S=P.front();
		A[S.y][S.x]=1;
		S.x+=x[l];
		S.y+=y[l];
		S.Z++;
		
		if(A[S.y][S.x]==1) continue;
		
		if(s[S.y][S.x]=='X'||S.y==h||S.x==w||S.x==-1||S.y==-1){
			S.x-=x[l];
			S.y-=y[l];
		}
		else if(s[S.y][S.x]=='.'){}
		else{
			if(C[S.c]==s[S.y][S.x]){
				S.c++;
				if(S.c==d+1){
				break;
				}
				while(!P.empty()){
				P.pop();
				
				}
			memset(A,0,sizeof(A));
			l=-1;
			}

		} 
		P.push(S);
	}
	printf("%d\n",S.Z);
	return 0;
}

Compiler output:
main.c:2:9: fatal error: iostream: No such file or directory
    2 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int H,W,N;
typedef pair<int,int> P;
#define INF 1e-9
const int MAX_N=1001;
char maze[MAX_N][MAX_N];
bool vis[MAX_N][MAX_N];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int d[MAX_N][MAX_N];
bool right(int x,int y)
{
    if(x>=0&&x<H&&y>=0&&y<W&&maze[x][y]!='X'&&!vis[x][y])
        return true;
    return false;
}
int bfs(int sx,int sy,int gx,int gy)
{
    queue<P> que;
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
            d[i][j]=INF;
    }
    que.push(P(sx,sy));
    d[sx][sy]=0;
    while(que.size())
    {
        P p=que.front();que.pop();
        if(p.first==gx&&p.second==gy)
            break;
        for(int i=0;i<4;i++)
        {
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(right(nx,ny))
            {
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}
int main()
{
    while(scanf("%d%d%d",&H,&W,&N)!=EOF)
    {
        getchar();
        for(int i=0;i<H;i++)
            scanf("%s",maze[i]);
        int ans=0;
        int sx=-1,sy=-1;
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
                if(maze[i][j]=='S')
                {
                    sx=i;sy=j;
                }
            if(sx!=-1&&sy!=-1)
                break;
        }
        for(int i=1;i<=N;i++)
        {
            memset(vis,false,sizeof(vis));
            int nx=-1,ny=-1;
            for(int j=0;j<H;j++)
            {
                for(int k=0;k<W;k++)
                {
                    if(maze[j][k]=='0'+i)
                    {
                        nx=j;ny=k;
                        break;
                    }
                }
                if(nx!=-1&&ny!=-1)
                    break;
            }
            ans+=bfs(sx,sy,nx,ny);
            sx=nx;
            sy=ny;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

/* AOJ0558 Cheese */
#include<bits/stdc++.h>
using namespace std;

const int DIRECTSIZE = 4;
struct _direct {
    int drow;
    int dcol;
} direct[DIRECTSIZE] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

const int N = 1000;
const int N2 = 10;
char grid[N][N], visited[N][N];
int h, w, n;
struct _factory {
    int row;
	int col;
} factory[N2];

struct _node {
    int row;
	int col;
	int level;
};

int bfs(int n, char goal) {
    memset(visited, 0, sizeof(visited));
    _node start={factory[n-1].row, factory[n-1].col, 0}, temp;
    visited[start.row][start.col] = 1;
    queue<_node> q;
    q.push(start);
    while(!q.empty()) {
        _node front = q.front();
        q.pop();
        for(int i=0; i<DIRECTSIZE; i++) {
            int nextrow = front.row + direct[i].drow;
            int nextcol = front.col + direct[i].dcol;
            if( 0 <= nextrow && nextrow < h && 0 <= nextcol && nextcol < w) {
                if(grid[nextrow][nextcol] == goal) {
                    return front.level + 1;
                }
				else if(visited[nextrow][nextcol] == 0 && grid[nextrow][nextcol] != 'X') {
                    visited[nextrow][nextcol] = 1;
                    temp.row = nextrow;
                    temp.col = nextcol;
                    temp.level = front.level + 1;
                    q.push(temp);
                }
            }
        }
    }
    return 0;
}

int main() {
    while (~scanf("%d %d %d", &h, &w, &n)){
        for(int i = 0; i < h; i++) {
			scanf("%s", grid[i]);
            for(int j = 0; j < w; j++) {
                if(grid[i][j] == 'S') {
                    factory[0].row = i;
                    factory[0].col = j;
				}
				else if(isdigit(grid[i][j])) {
                    factory[grid[i][j] - '0'].row = i;
                    factory[grid[i][j] - '0'].col = j;
                }
            }
		}
        int minstep = 0;
        char goal = '1';
        for(int i=1; i<=n; i++) {
            minstep += bfs(i, goal);
            goal++;
        }
        printf("%d\n", minstep);
    }
    return 0;
}

Compiler output:
main.c:2:9: fatal error: bits/stdc++.h: No such file or directory
    2 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

//AOJ-0558
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

char map[1010][1010];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int vis[1010][1010];
int m, n, N;
struct node{
	int x, y, t;
};

node bfs(int x, int y, int k)
{
	memset(vis, 0, sizeof(vis));
	queue<node> q;
	vis[x][y] = 1;
	node s; s.x = x; s.y = y; s.t = 0;
	q.push(s);
	while(!q.empty())
	{
		node p = q.front(); q.pop();
		vis[p.x][p.y] = 1;
		node e;
		if(map[p.x][p.y] == k + '0') return p;
		for(int i = 0; i < 4; i++)
		{
			e.x = p.x + dx[i];
			e.y = p.y + dy[i];
			if(map[e.x][e.y] == 'X' || vis[e.x][e.y] == 1) continue;
			e.t = p.t + 1;
			q.push(e);
		}
	}
	s.x = s.y = s.t = -1;
	return s;
}
void clear(){
	for(int i = 0; i < 1010; i++)
	  for(int j = 0; j < 1010; j++)
	    map[i][j] = 'X';
}
int main()
{
	while(scanf("%d %d %d", &n, &m, &N) != EOF)
	{
		clear();
		node s;
		for(int i = 1; i <= n; i++){
			getchar();
			for(int j = 1; j <= m; j++){
			   map[i][j] = getchar();
			   if(map[i][j] == 'S'){
			   	 map[i][j] = '.';
			   	 s.x = i; s.y = j; s.t = 0;
			   }
			}	
		}
		int ans = 0;
		for(int i = 1; i <= N; i++)
		{
			s = bfs(s.x, s.y, i);
			map[s.x][s.y] = '.';
			ans += s.t;
		}
		printf("%d\n", ans);
	}
	return 0; 
}


Compiler output:
main.c:2:10: fatal error: cstdio: No such file or directory
    2 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>  
#include<string.h>  
#include<queue>  
using namespace std;  
const int maxn=1005;  
int n,m,k,dx[]={-1,1,0,0},dy[]={0,0,1,-1},vis[maxn][maxn];  
char map[maxn][maxn];  
struct maze  
{  
    int x,y,time;  
};  
maze bfs(int bx,int by,char ch)  
{  
    memset(vis,0,sizeof(vis));  
    queue<maze> q;  
    maze st={bx,by,0};  
    q.push(st);vis[bx][by]=1;  
    while(!q.empty())  
    {  
        st=q.front();q.pop();  
        if(map[st.x][st.y]==ch)  
        {  
            return st;  
        }  
        for(int i=0;i<4;++i)  
        {  
            int tx=st.x+dx[i],ty=st.y+dy[i];  
            if(tx<0||tx>=n||ty<0||ty>=m||map[tx][ty]=='X') 
            {  
                continue;  
            }  
            maze tp={tx,ty,st.time+1};  
            if(!vis[tx][ty])  
            {  
                vis[tx][ty]=1;  
                q.push(tp);  
            }  
        }  
    }  
}  
int main()  
{  
    while(~scanf("%d%d%d",&n,&m,&k))  
    {  
        int bx,by;  
        for(int i=0;i<n;++i)  
        {  
            scanf("%s",map[i]);  
            for(int j=0;j<m;++j)  
            {  
                if(map[i][j]=='S')  
                {  
                    bx=i;by=j;  
                    map[i][j]='0';  
                }  
            }  
        }  
        int ans=0;  
        for(int i=0;i<k;i++)  
        {  
            maze tp=bfs(bx,by,map[bx][by]+1);  
            ans+=tp.time;  
            bx=tp.x;by=tp.y;  
        }  
        printf("%d\n",ans);  
    }  
    return 0;  
}


Compiler output:
main.c:3:9: fatal error: queue: No such file or directory
    3 | #include<queue>
      |         ^~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cstdio>

#define INF 1 << 29

using namespace std;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
char f[1003][1003];
int visited[1003][1003][10];

class S{
public:
    int x;
    int y;
    int lvl;
    int step;

    S(int x, int y, int lvl, int step):x(x),y(y),lvl(lvl),step(step){}
};

int main(){
    int h,w,lvl,sx,sy,gx,gy;
    cin >> h >> w >> lvl;
    fill((char *)f, (char *)f+1003*1003, 'X');
    fill((int *)visited, (int *)visited+1003*1003*10, INF);

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> f[i][j];
            if(f[i][j] == 'S'){
                sx = j;
                sy = i;
            }else if(f[i][j] == lvl + '0'){
                gx = j;
                gy = i;
            }
        }
    }
    deque<S> q;
    q.push_back(S(sx,sy,1,0));
    visited[sy][sx][1] = 0;
    int px,py,tmplvl,tmpstep;
    while(!q.empty()){
        px = q.front().x;
        py = q.front().y;
        tmplvl = q.front().lvl;
        tmpstep = q.front().step;
        q.pop_front();

        //printf("current:(y = %d, x = %d, lvl = %d, step = %d)\n", py,px,tmplvl,tmpstep);

        if(py == gy && px == gx && tmplvl == lvl+1){
            break;
        }
        visited[py][px][tmplvl] = tmpstep;
        for(int i=0;i<4;i++){
            int nx = px + dx[i];
            int ny = py + dy[i];

            if(f[ny][nx] != 'X'){
                if(f[ny][nx] == tmplvl +'0'){
                    q.push_back(S(nx,ny,tmplvl+1,tmpstep+1));
                }else{
                    if(tmpstep + 1 < visited[ny][nx][tmplvl]){
                        q.push_back(S(nx,ny,tmplvl,tmpstep+1));
                        visited[ny][nx][tmplvl] = tmpstep+1;
                    }
                }
            }
        }
    }
    cout << tmpstep << endl;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cstdio>

#define INF 1 << 29

using namespace std;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
char f[1003][1003];
bool visited[1003][1003][10];

class S{
public:
    int x;
    int y;
    int lvl;
    int step;

    S(int x, int y, int lvl, int step):x(x),y(y),lvl(lvl),step(step){}
};

int main(){
    int h,w,lvl,sx,sy,gx,gy;
    cin >> h >> w >> lvl;
    fill((char *)f, (char *)f+1003*1003, 'X');
    fill((bool *)visited, (bool *)visited+1003*1003*10, false);

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> f[i][j];
            if(f[i][j] == 'S'){
                sx = j;
                sy = i;
            }else if(f[i][j] == lvl + '0'){
                gx = j;
                gy = i;
            }
        }
    }
    deque<S> q;
    q.push_back(S(sx,sy,1,0));
    visited[sy][sx][1] = true;
    int px,py,tmplvl,tmpstep;
    while(!q.empty()){
        px = q.front().x;
        py = q.front().y;
        tmplvl = q.front().lvl;
        tmpstep = q.front().step;
        q.pop_front();

        //printf("current:(y = %d, x = %d, lvl = %d, step = %d)\n", py,px,tmplvl,tmpstep);

        if(py == gy && px == gx && tmplvl == lvl+1){
            break;
        }
        visited[py][px][tmplvl] = tmpstep;
        for(int i=0;i<4;i++){
            int nx = px + dx[i];
            int ny = py + dy[i];

            if(f[ny][nx] != 'X'){
                if(f[ny][nx] == tmplvl +'0'){
                    q.push_back(S(nx,ny,tmplvl+1,tmpstep+1));
                }else{
                    if(!visited[ny][nx][tmplvl]){
                        q.push_back(S(nx,ny,tmplvl,tmpstep+1));
                        visited[ny][nx][tmplvl] = true;
                    }
                }
            }
        }
    }
    cout << tmpstep << endl;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef struct {
   short cost, x, y;
}Point;//螳壻ケ我ク?クェ扈捺桷菴鍋畑譚・蟄伜お豈丈クェ蟾・蜴ら噪蝮先?菴咲スョ蜥悟・カ驟ェ逧??
int H, W, N;
vector<Point> factory;
char map[1000][1002];
short dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
bool myfunction(Point a, Point b)
{
    return a.cost < b.cost;
}

int bfs(int sx, int sy, int ex, int ey);
int main()
{
    cin>>H>>W>>N;
    int sx, sy;
    for(int i = 0; i < H; i++){
        cin>>map[i];
        for(int j = 0; j < W; j++){
            if( 1 <= (map[i][j]-'0') && (map[i][j]-'0') <= N){
                Point p;
                p.x = i, p.y = j, p.cost = map[i][j] - '0';
                factory.push_back(p);//謚雁キ・蜴ら噪陦ィ遉コ謾セ蛻ー蜿ッ蜿俶焚扈?クュ
            }
            if(map[i][j] == 'S')
               sx = i, sy = j; //隶ー蠖戊オキ蟋倶ス咲スョ逧?攝譬?        }
    }

    sort(factory.begin(), factory.end(), myfunction);

    int ans = 0;
    int start_x = sx, start_y = sy;
    for(int i = 0; i < factory.size(); i++){
        ans += bfs(start_x, start_y, factory[i].x, factory[i].y);
        start_x = factory[i].x;  start_y = factory[i].y;
    }

    cout<<ans<<endl;

    return 0;
}


int bfs(int sx, int sy, int ex, int ey)
{
   queue<Point> q;
   Point s;
   s.x = sx; s.y = sy; s.cost = 0;//蛻晏ァ句喧蠑?ァ狗噪豁・謨ー荳コ0
   q.push(s);//謚願オキ蟋狗せ謾セ蛻ー髦溷?荳ュ
   while(!q.empty()){
     s = q.front();
     q.pop();
     for(int i = 0; i < 4; i++){
       int xx,yy;
       xx = s.x + dx[i]; yy = s.y + dy[i];
       if(xx == ex && yy == ey) return s.cost+1;//螯よ棡蟾イ扈丞芦莠?サ育せ蛻呵ソ泌屓螳?噪豁・謨ー
       if(xx >= 0 && xx < H && yy >= 0 && yy < W && map[xx][yy] != 'X'){
           Point now;
           now.x = xx; now.y = yy; now.cost = s.cost + 1;
           cout<<now.x<<'\t'<<now.y<<'\t'<<now.cost<<endl;
           q.push(now);
       }
     }//for()
   }//while()
}//bfs()

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.