Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
const IDEAL = 22

type Person struct {
	Id int
	Weight float64
	Height float64
	BMI float64
}

type LessFunc func(p1, p2 *Person) bool
type multiSorter struct {
	People []Person
	less []LessFunc
}
func (ms *multiSorter) Sort(people []Person) {
	ms.People = people
	sort.Sort(ms)
}
func OrderBy(less ...LessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.People)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.People[i], ms.People[j] = ms.People[j], ms.People[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.People[i], &ms.People[j]
	var k int
	for k = 0; k < len(ms.less); k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	id := func(p1, p2 *Person) bool {
		return p1.Id < p2.Id
	}
	bmi := func(p1, p2 *Person) bool {
		return math.Abs(p1.BMI-22) < math.Abs(p2.BMI-22)
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		People := make([]Person, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpid, _ := strconv.Atoi(buf[0])
			tmpheight, _ := strconv.ParseFloat(buf[1], 64)
			tmpweight, _ := strconv.ParseFloat(buf[2], 64)
			People = append(People,
			 		Person{tmpid,
			 		tmpheight/100,
			 		tmpweight,
			 		tmpweight/(tmpheight/100*tmpheight/100)})
		}
		OrderBy(bmi, id).Sort(People)
		// bestID := People[0].Id
		bestBMI := People[0].BMI
		for _, p := range People {
			if p.BMI == bestBMI {
				fmt.Println(p.Id)
			}
		}
	}
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    double m, kg;
    while(cin >> n, n){
        int num, ans, ansmbi = 2 << 24;
        rep(i, n){
            cin >> num >> m >> kg;
            m /= 100;
            double mbi = kg / (m * m);
            double re = 22 - mbi > 0 ? 22 - mbi: mbi - 22;
            if(ansmbi > re){
                ansmbi = re;
                ans = num;
            }
        }
        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    double m, kg;
    while(cin >> n, n){
        double num, ans = 2 << 24, ansmbi = 2 << 24;
        rep(i, n){
            cin >> num >> m >> kg;
            m /= 100;
            double mbi = kg / (m * m);
            double re = 22 - mbi > 0 ? 22 - mbi: mbi - 22;
            if(ansmbi >= re){
                ansmbi = re;
                if(ans > num)
                    ans = num;
            }
        }
        cout << ans << endl;
    }
}

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

struct hoge{
	int i;
	double bmi;
};

int main(){
	int ini, h, w, n, ans;
	double hm;
	hoge set[1000000];
	
	while(1){
		ans = 0;
		cin >>n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >>ini >>h >>w;
			hm = (h / 100.0) * (h / 100.0);
			set[i].i = ini;
			set[i].bmi = w / hm;
		}
		for(int i = 0; i < n; i++){
			if(abs(set[i].bmi - 22) < abs(set[ans].bmi - 22)){
				ans = i;
			}
		}
		cout <<set[ans].i <<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

double calc(double height,double weight){
	return fabs(22.0 - (weight/((height*height)/10000)));
}

int main(){

	int n,best_index,tmp_index;
	double best_score,tmp_score,height,weight;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		scanf("%d %lf %lf",&best_index,&height,&weight);
		best_score = calc(height,weight);

		if(n > 1){
			for(int i = 1; i < n; i++){
				scanf("%d %lf %lf",&tmp_index,&height,&weight);
				tmp_score = calc(height,weight);
				if(tmp_score < best_score){
					best_score = tmp_score;
					best_index = tmp_index;
				}else if(fabs(tmp_score-best_score) < 0.00000001){
					if(tmp_index < best_index){
						best_index = tmp_index;
					}
				}
			}
		}

		printf("%d\n",best_index);

	}

    return 0;
}

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

#define BESTBMI 22
#define MAX 10000

class CDATA {
public:
  int stnum;
  double hei, wei;
  int bmi;
  
  void setBMI() {
    bmi = wei/(hei*hei);
  }
  
  bool operator< (const CDATA &t) const {
    if(abs(22-bmi)==abs(22-t.bmi)) return stnum<t.stnum;
    else return abs(22-bmi) < abs(22-t.bmi);
  }
};

int main() {
  int n;
  double h;
  CDATA person[MAX]; 
  
  while(cin>>n, n) {
    for(int i=0; i<n; i++) {
      cin>>person[i].stnum>>h>>person[i].wei;
      person[i].hei=h/100;
      person[i].setBMI();
    }
    
    stable_sort(person, person+n);
    
    cout<<person[0].stnum<<endl;
    
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int man[2];
        double bmi[2],h,w;
        cin>>man[0]>>h>>w;
        h/=100;
        bmi[0]=w/(h*h)-22;
        if(bmi[0]<0)bmi[0]*=-1;
        for(int i=1;i<n;i++){
            cin>>man[1]>>h>>w;
            h/=100;
            bmi[1]=w/(h*h)-22;
            if(bmi[1]<0)bmi[1]*=-1;
            if(bmi[1]<bmi[0]||bmi[0]==bmi[1]&&man[1]<man[0]){
                bmi[0]=bmi[1];
                man[0]=man[1];
            }
        }
        cout<<man[0]<<endl;
    }
}

C++: #include<iostream>
#include<cmath>
#define INF 1000000
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {		
		int aa;
		long double sa = INF;

		for (int i = 0;i < n;i++) {
			long double a, b, c;
			cin >> a >> b >> c;
		long double bmi = c / (b*b / 10000);

			if (sa > abs(22 - bmi)) {
				aa = a;
				sa = abs(22 - bmi);
			}
		}

		cout << aa << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<pair<double, int>> v;
        for (int i = 0; i < n; ++i) {
            int p; int h, w;
            cin >> p >> h >> w;
            v.emplace_back(abs(22-1e4*w/h/h), p);
        }
        cout << min_element(v.begin(),v.end())->second << "\n";

    }
    return 0;
}

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

int main(void){
    int n,num,h,w;
    
    while(1){
        int best = 22;
        int tmp,bn;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++){
            cin >> num >> h >> w;
            
            double nh = (double)h / 100;
            int BMI = w / (nh*nh);
            if(!i){
                tmp = abs(BMI-best);
                bn = num;
                continue;
            }
            
            if(tmp > abs(BMI-best)){
                tmp = abs(BMI-best);
                bn = num;
            }
        }
        cout << bn << endl;
    }

    return 0;
}