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 <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T T sq(T x){ return x * x; }
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r.begin()); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v){ return accumulate(v.begin(), v.end()); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

struct Field {
  Field(int w, int h) : w(w), h(h) {}
  bool invalid(int x, int y){ return x < 0 || w <= x || y < 0 || h <= y; }
  const int w, h;
};

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n;
  while (n = in()){
    vector<pair<double, int> > hs;
    for (int i = 0; i < n; i++){
      int id, cm, kg;
      id = in();
      cm = in();
      kg = in();
      double bmi = kg / sq(cm / 100.0);
      hs.push_back(make_pair(abs(22 - bmi), id));
    }
    sort(hs);
    printf("%d\n", hs[0].second);
  }
  return (0);
}

C++: #include<iostream>

using namespace std;

int main(){
  int n;

  while(cin >> n){

    //int n;

    // cin >> n;

    if(n == 0) break;

    int min = 100000000;
    int minnum;
    double bmi[n];

    for(int i = 0; i < n; i++){
      int num;
      double tall, wei;

      cin >> num >> tall >> wei;

      bmi[i] = wei / (tall / 100) / (tall / 100);

      bmi[i] -=22;

      if(bmi[i] < 0) bmi[i] *= -1;
 
      if(min > bmi[i]){
	minnum = num;
	min = bmi[i];
      }
    }

    cout << minnum << endl;
  }


  return 0;

}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int n;
	while(cin>>n,n){
		vector<pair<double,int> > v;
		FOR(i,n){
			int id,h,w; cin>>id>>h>>w;
			double bmi = w / (double)(h*h) * 10000;
			v.push_back(make_pair(abs(bmi-22),id));
		}
		cout << (*(min_element(v.begin(),v.end()))).second << endl;

	}

	return 0;
}

C++: #include <iostream>
#include <map>
#include <utility>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pdi pair<double, int>
const double EPS = 1e-10;
int main(){
	int n, h, w;
	pdi a;
	while(cin >> n, n) {
		vector<pdi> v;
		rep(i,n) {
			cin >> a.second;
			cin >> h >> w;
			a.first = abs(w / ((h/100.0) * (h/100.0)) - 22);
			v.push_back(a);
		}
		sort(v.begin(), v.end());

		cout << v[0].second << endl;
		int i = 1;
		while(v[i+1].first - v[i].first < EPS) {
			cout << v[i].second << endl;
			i++;
		}
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
const double EPS = 1e-10;

int main(){
  int n;
  int id, w, h;
  int best;
  double dif;
  while(cin >> n && n){
    best = 0;
    dif = 1e10;
    rep(i, n){
      cin >> id >> h >> w;
      double d = abs(22.0 - (double)w / ((double)h * h) * 10000);
      if(d < dif || abs(d - dif) < EPS && id < best){
	dif = d;
	best = id;
      }

    }
    cout << best << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
 int c,h,w,n;
 double best=100.0;
 int set;
 while(true){
 cin>>n;
 if(n==0)
 break;
 for(int i=0;i<n;i++){
  cin>>c>>h>>w;
  double r=h*10000/w/w;
  if(abs(22.0-r)<best){
      set=c;
      best=abs(22.0-r);
  }
 }
 cout<<set<<endl;
 }
 return 0;   
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n, i;
double h, w;

double BMI(double h, double w){
	return w / (h*0.01*h*0.01);
}

int main(){
	while (cin >> n){
		double bmi = INF;
		ll index = INF;
		REP(j, n){
			cin >> i >> h >> w;
			double a = fabs(BMI(h, w) - 22.0) - fabs(bmi - 22.0);
			if (a < -EPS){
				bmi = BMI(h, w);
				index = i;
			}
			if (fabs(a) < EPS){
				index = min(i, index);
			}
		}
		cout << index << endl;
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int n,i;
int main(){
	int a,out;
	double h,w,to,tn;
	while(cin >> n && n){
		out = 0;
		tn = 100;
		for(i=0;i<n;i++){
			cin >> a >> h >> w;
			h /= 100;
			to = fabs(22-(w/(h*h)));
			if(tn > to) {
				out = a;
				tn = to;
			}
			else if(tn == to && a < out){
				out = a;
				tn = to;
			}
		}
		cout << out << endl;
	}
	return 0;
}