Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		s, _ := strconv.Atoi(input[0])
		e, _ := strconv.Atoi(input[1])
		a := make([]int, 0)
		if s <= 5 {
			if s > e {
				for j := s; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := s; j < e+1; j++ {
					a = append(a, j)
				}
			}
		} else if s < e {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
		} else {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
			if e <= 5 {
				for j := 5; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := 5; j > 0; j-- {
					a = append(a, j)
				}
				for j := 0; j < e+1; j++ {
					a = append(a, j)
				}
			}
		}
		for i, v := range a {
			if i != len(a)-1 {
				fmt.Printf("%d ", v)
			} else {
				fmt.Println(v)
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
    for(int i=0,x,y;i<n;i++){
        cin>>x>>y;
        if(x<6&&y<6){
            int sum=y-x;
            if(sum>0){
                cout<<num[x];
                for(int j=x+1;j<=y;j++)cout<<" "<<num[j];
                cout<<endl;
            }
            else {
                cout<<num[15-x];
                for(int j=16-x;j<16-y;j++)cout<<" "<<num[j];
                cout<<endl;
            }
        }
        else{
            cout<<num[x];
            for(int j=x+1;num[j-1]!=y;j++){
                if(j==16)j=1;
                cout<<" "<<num[j];
            }
            cout<<endl;
        }
    }
}

C++: #include <iostream>
#include <string>
using namespace std;

string str = "6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9";
string getstr(char s, char d){
	int i,j;
	for(i=0;str[i]!=s;i++);
	for(j=i;str[j]!=d;j++) if(str[j]==s) i=j;
	return str.substr(i, j-i+1);
}
main(){
	int n,a,b;
	cin >> n;
	while(n--){
		cin >> a >> b;
		cout << getstr(a+'0', b+'0') << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;

int main(){
	int n;
	int bus[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int a, b;
		scanf(" %d %d", &a, &b);
		
		if(a==0 || 5<a){ //1通りしかありえない
			int start=0, goal;
			while(bus[start] != a) start++;
			
			goal=start;
			while(1){
				printf("%d", bus[goal%15]);
				if(bus[goal%15] == b) break;
				goal++;
			}
			printf("\n");
		}
		else{ //2通りある
			int start=0, goal, count1=0, count2=0;
			
			while(bus[start] != a) start++;
			goal=start;
			while(bus[goal%15] != b){
				goal++;
				count1++;
			}
			
			start++;
			int tmp=0;
			while(bus[start%15] != a) start++;
			goal=start;
			while(bus[goal%15] != b){
				goal++;
				count2++;
			}
			
			if(count1 < count2) goal=a;
			else goal=15-a;
			
			bool flag=false;
			while(1){
				if(flag) printf(" ");
				
				printf("%d", bus[goal%15]);
				if(bus[goal%15] == b) break;
				goal++;
				flag=true;
			}
			printf("\n");
			
		}
		
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

void print_stops(int from, int to) {
    if (from <= 5 && to <= 5) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; i >= to; i--) {
                cout << i << ' ';
            }
        }
    } else if (from <= 5 && 6 <= to && to <= 9) {
        for (int i = from; i <= to; i++) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && to <= 5) {
        for (int i = from; i <= 9; i++) {
            cout << i << ' ';
        }
        for (int i = 5; to <= i; i--) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && 6 <= to && to <= 9) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; to <= i; i++) {
                cout << i << ' ';
            }
        }
    }
    cout << endl;
}

int main() {
    int n; cin >> n;
    while (n--) {
        int from, to;
        cin >> from >> to;
        print_stops(from, to);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int F = 9;

int main()
{
    int s, g, n; 
    while( cin >> n && n)
    {
        REP(n)
        {
            vector<int> ans;
            cin >> s >> g;
            if(s <= 5 && g <= 5)//OK
            {
                if( s < g)for(int j = s;j <= g;j++) ans.push_back(j);

                if(s > g)for(int j = s; j >= g;j--) ans.push_back(j);
            }
            if( s>5 && g <= 5)//OK
            {
                for(int j = s; j<= F;j++) ans.push_back(j);
                for(int j = 5; j >= g;j--) ans.push_back(j);
            }
            if(s <= 5 && g> 5)//OK
                for(int j = s; j<=g;j++) ans.push_back(j);

            if(s >5 && g > 5)
            {
                if( s < g)for(int j = s; j<=g;j++) ans.push_back(j);
                if( s > g )
                {
                    for(int j = s; j<=F;j++) ans.push_back(j);
                    //for(int j = 5; j>=0;j--) ans.push_back(j);
                    for(int j = 5;j <=g;j++) ans.push_back(j);
                }
            }

            rep(j,ans.size()){ cout << ans[j]; if(j == ans.size()-1) break; cout << " ";}
            cout << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a[15] = { 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1 };
	int s, t;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s >> t;
		int sum = 100000, sum2 = 100000, s2 = s,count=0;
		bool sumb = false, sum2b = false;
		vector<int> go;
		vector<int>go2;
		for (int j = 0; j < 15; j++)
		{
			if (a[j] == s) {
				s2 = j;
				while (a[s2] != t) {
					if (count == 0) {
						if (!sumb) {
							sum = 0; sumb = true;
						}
						go.push_back(a[s2]);
						sum++;
					}
					else {
						if (!sum2b) {
							sum2 = 0; sum2b = true;
						}
						go2.push_back(a[s2]);
						sum2++;
					}
					s2++;
					if (s2 > 14) s2 = 0;
				}
				if (count == 0) {
					go.push_back(t);
					sum++;
				}
				else {
					go2.push_back(t);
					sum2++;
				}
				count++;
				s2 = s;
			}
		}
		if (sum < sum2) {
			for (int i = 0; i < sum; i++) {
				if (i == 0) cout << go[i];
				else cout << " " << go[i];
			}
			cout << endl;
		}
		else {
			for (int i = 0; i < sum2; i++) {
				if (i == 0) cout << go2[i];
				else cout << " " << go2[i];
			}
			cout << endl;
		}
	}
}