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>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    string s="";double out=0;
    rep(i,n){
      string tmp;double a,b;
      cin>>tmp>>a>>b;
      a/=100;
      if(s==""){
	s=tmp;
	out=abs(b/a/a-22.0);
      }else if(out>abs(b/a/a-22.0)){
	out=abs(b/a/a-22.0);
	s=tmp;
      }
      //cout<<tmp<<" "<<b/a/a<<" "<<abs(b/a/a-22.0)<<endl;
    }
    cout<<s<<endl;
  }
}

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

class Point{
public:
  int n;
  double sa;
  Point (int n = 0, double sa = 0):n(n),sa(sa){}
  bool operator < (const Point &p) const{
    return sa < p.sa;
  }
};

main(){
  int i,j,n;
  Point p[1000000];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++){
      double h,w;
      cin >> p[i].n >> h >> w;
      p[i].sa = w / pow(h/100,2) - 22.0;
      if(p[i].sa < 0.0) p[i].sa *= -1.0;
    }
    sort(p,p+n);

    cout << p[0].n << endl;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		vector<pair<double, int>> bmi(n);
		rep(i, n) {
			int p; double h, w; cin >> p >> h >> w;
			bmi[p - 1].second = p;
			bmi[p - 1].first = abs(w / ((h / 100.)*(h / 100.)) - 22);
		}
		Cout(min_element(all(bmi)) - bmi.begin() + 1);
	}
}

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

int main() {
  while(1) {
    int n, x;
    double min=1000000;
    cin >> n;
    if(n==0) break;

    for(int i=0; i<n; i++) {
      int name;
      double h, w, bmi;
      cin >> name >> h >> w;
      bmi=w/(h*h)*10000;
      if(abs(bmi-22)<min) {
	min=abs(bmi-22);
	x=name;
      }
    }
    cout << x << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int index;
		double Min = (double)INT_MAX;
		rep(i, n) {
			int I; double h, w; cin >> I >> h >> w; h /= 100;
			double d = abs(22. - (w / (h*h)));
			if (d < Min) {
				index = I; Min = d;
			}
			if (d == Min) {
				index = min(index, I);
			}
		}
		cout << index << endl;
	}
}

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

int main(){
	int n;
	while(cin >> n,n){
		int num;
		double mi = 1e+9;
		for(int i = 0;i < n;i++){
			int p;
			double h,w;
			cin >> p >> h >> w; h /= 100.0;
			double d = abs(22.0 - w / h / h);
			if(abs(mi - d) < 1e-8) num = min(num,p);
			else if(mi > d) {
				num = p;
				mi = d;
			}
		}
		cout << num << endl;
	}
	return 0;
}

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

int main(){
    int n;
    while(cin >> n, n != 0){
        int ideal_id;
        double bmi, weight, height, min_diff = 100000;
        int id;
        for(int i=1; i<=n; i++){
            cin >> id >> height >> weight;
            bmi = weight/((height/100.0)*(height/100.0));
            if(min_diff > abs(bmi-22.0)){
                min_diff = abs(bmi-22.0);
                ideal_id = id;
            }
        }
        cout << ideal_id << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair

int main() {
	while (true) {
		int n;
		pair<int, double> ans = MP(0, (1<<29));
		cin >> n;
		if (n == 0) break;

		REP(i, n) {
			double a, b, c, bmi;
			scanf("%lf %lf %lf", &a, &b, &c);
			bmi = c / (b/100 * b/100);

			if (ans.second > abs(22 - bmi)) {
				ans.first = a;
				ans.second = abs(22 - bmi);
			}
		}
		cout << ans.first << endl;
	}
	return 0;
}

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

int main() {
int n,num;
double ta,omo,bmi;
while(cin>>n){
	if(n==0){
		break;
	}
	double max=100000,sa;
	int best=1000000;
for(int k=0;k<n;k++){
	cin>>num>>ta>>omo;
	bmi=omo*10000/(ta*ta);
	if(bmi-22<0){
		sa=22-bmi;
	}
	else{
		sa=bmi-22;
	}
	if(sa<max||(sa==max&&num<best)){
		best=num;
		max=sa;
	}
}
cout<<best<<endl;
}
	return 0;
}