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++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < ((k)+(n)); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,const _Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    int n;
    while(cin >> n && n){
        double min = 1e9; int id = -1;
        REP(i,n){
            int n, h, w;
            cin >> n >> h >> w;
            double bmi = abs(22 - 10000.0 * w / (h*h));
            if(min > bmi || (abs(min-bmi) < EPS && id > n)){
                min = bmi; id = n;
            }
        }
        cout << id << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#define int double
using namespace std;

signed main()
{
	int a;
	while (cin >> a, a) {
		map<int, int>s;
		for (int b = 0; b < a; b++) {
			int c, d, e;
			cin >> c >> d >> e;
			int f = e / d / d * 10000;
			if (f > 22) {
				s.insert(pair<int, int>(f-22,c));
			}
			else {
				s.insert(pair<int, int>(22-f,c));
			}
		}
		auto j = s.begin();
		cout << j->second << endl;
	}
}

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


class person{
public:
	int num;
	double w;
	double h;
	double bmi;
	person(int n,double _w,double _h,double _bmi){
		num=n;w=_w;h=_h;bmi=_bmi;
	}
	double getBMIPoint(){
		if(h!=0)bmi=w/((h/100)*(h/100));
		if(bmi<22){
			return 22-bmi;
		}
		else {
			return bmi-22;
		}
	}
	void print(){
		cout<<num<<" "<<w<<" "<<h<<""<<bmi<<endl;
	}
};
int
main(){
	
	for(int d;cin>>d;){
		if(!d)break;
		person stable=person(0,0,0,100);
		for(int i=0;i<d;i++){
		//	stable.print();
			int num;
			double w,h;
			cin>>num>>h>>w;
			person p=person(num,w,h,0);
		//	p.print();
		//	cout<<p.getBMIPoint()<<endl;
			if(stable.getBMIPoint()>=p.getBMIPoint()){
					if(stable.getBMIPoint()==p.getBMIPoint()){
						if(stable.num<p.num)continue;
					}
					stable=p;
			}
			
		}
		cout<<stable.num<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

typedef pair<double,string> p;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		vector<p> vec(n);
		rep(i,n){
			double weight[2];
			string num;
			cin>>num>>weight[0]>>weight[1];
			vec[i].first=abs(22-weight[1]/pow(weight[0]*pow(10,-2),2));
			vec[i].second=num;
		}
		sort(vec.begin(),vec.end());
		cout<<vec[0].second<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  while(cin >> n , n){
    int name;
    int ans;
    double near = -1;
    for(int i=0;i<n;i++){
      double w,h;
      cin >> name >> h >> w;
      double tmp = w / ((h/100)*(h/100));
      if(near == -1 || fabs(22.0-tmp) < fabs(22.0-near)){
	near = tmp;
	ans = name;
      }
      else if(fabs(22.0-tmp) == fabs(22.0-near)){
	if(name < ans){
	  name = ans;
	}
      }
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int bmi(double h, double w){
	return w/((h/100)*(h/100));
}

int main(){
	int n, p;
	double h, w;
	const double c = 22;
	while(true){
		cin >> n;
		if(n == 0)
			return 0; 
		int num;
		double diff;
		for(int i = 0; i < n; i++){
			cin >> p >> h >> w;
			if(i == 0){
				num = p;
				diff = abs(bmi(h,w) - c);
			}else{
				double k = abs(bmi(h,w) - c);
				if(diff > k){
					diff = k;
					num = p;
				}else if(diff == k){
					if(num > p)
						num = p;
				}
			}
		}
		cout << num << endl;
	}

}

BMI = ??????(kg) / (??????(m))2