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 _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-8;

int main(){

	int i,n;
	double h,w;
	
	while(~scanf("%d",&n)){
		if(n==0) break;
		double diff = 1000000;
		int res=10000000;

		for(int j=0;j<n;j++){
			scanf("%d %lf %lf",&i,&h,&w);
			if(diff >= abs(22.0-(w / ((h/100.0)*(h/100.0))))){
				diff = abs(22.0-(w / ((h/100.0)*(h/100.0))));
				res = min(res,i);
			}
		}
		printf("%d\n",res);
	}
}

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

int main() {
    int N;
    while (cin >> N, N) {
        int id = 1000000000;
        double bmi = 2000.0;
        for (int i = 0; i < N; i++) {
            int d;
            double h, w;
            cin >> d >> h >> w;
            h /= 100.0;

            if (bmi > abs(22.0 - (w / (h * h)))) {
                id = d;
                bmi = abs(22.0 - (w / (h * h)));
            } else if (bmi == abs(22.0 - (w / (h * h)))) {
                id = min(d, id);
            }
        }

        cout << id << endl;
    }

    return 0;
}

C++: #include <cmath>
#include <iostream>
using namespace std;
int n, d, h, w, p;
int main() {
	while(scanf("%d", &n), n) {
		double s = 1.0e6;
		for(int i = 0; i < n; i++) {
			scanf("%d%d%d", &d, &h, &w);
			double r = abs(22.0 - 10000.0 * w / h / h);
			if(r < s) r = s, p = d;
		}
		printf("%d\n", p);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<double,int> pdi;

const double EPS=1e-10;

bool operator<(const pdi& a,const pdi& b)
{
	return abs(a.first-b.first)<EPS?a.second<b.second:a.first<b.first;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<pdi> people;
		rep(i,n){
			int id,h,w; cin>>id>>h>>w;
			people.push_back(mp(abs(22-w/(h*h*1e-4)),id));
		}
		cout<<min_element(allof(people))->second<<endl;
	}
	
	return 0;
}

C++: #include <cmath>
#include <cstdio>
int n, d, h, w, p;
int main() {
	while(scanf("%d", &n), n) {
		double s = 1.0e6;
		for(int i = 0; i < n; i++) {
			scanf("%d%d%d", &d, &h, &w);
			double r = abs(22.0 - 10000.0 * w / h / h);
			if(r < s) r = s, p = d;
		}
		printf("%d\n", p);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[1000],h[1000],w[1000],x,y,i;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++) {
			scanf("%d %d %d",&p[i],&h[i],&w[i]);
			h[i]=(double)w[i]/(h[i]*h[i])*10000;
//		printf("p=%d h=%d\n",p[i],h[i]);
			if(h[i]<0)  h[i]=h[i]*-1;
			h[i]=h[i]-22;
			if(h[i]<0)  h[i]=h[i]*-1;
		}
		x=p[0]; y=h[0];
		for(i=1;i<n;i++){
			if(y>h[i]){
				x=p[i];  y=h[i];
			}
		}
		printf("%d\n",x);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
#include<utility>

typedef std::pair<double, int> P;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		P ans( 201, 1000001 );
		
		while( n-- )
		{
			int i; 
			double h, w;
			std::cin >> i >> h >> w;
			h /= 100.0;
			ans = std::min( ans, P( abs( w / ( h * h ) - 22 ), i ) );
		}

		std::cout << ans.second << std::endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int n;
	int bango,meter,taiju;
	int risoban;
	double riso;
	double riri;
	double BMI;

	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> bango >> meter >> taiju;
			BMI = (double)taiju / ((double)pow(meter,2) / 10000.0);
			if (i == 0) {
				risoban = bango;
				if (BMI < 22.0) {
					riso = 22.0 - BMI;
				} else {
					riso = BMI - 22.0;
				}
			} else {
				riri = BMI - 22.0;
				if (riri < 0) {
					riri = -riri;
				}
				if (riri < riso) {
					riso = riri;
					risoban = bango;
				}
			}
		}
		cout << risoban << endl;
	}
	return 0;
}

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

int main(){
    typedef pair<int,long double> P;
    int n,tmp;
    long double tmp1,tmp2;
    while(cin >> n,n){
        P p;
        p.first = 1000001;
        p.second = 10000;
        for(int i=0;i<n;i++){
            cin >> tmp >> tmp1 >> tmp2;
            tmp1 /= 100;
            tmp1 *= tmp1;
            tmp2 /= tmp1;
            tmp2 -= 22.000;
            tmp2 = fabs(tmp2);
            if(tmp2 < p.second || (tmp2 <= p.second && tmp < p.first)){
                p.first = tmp;
                p.second = tmp2;
            }
        }
        cout << p.first << endl;
    }
}

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

class humman
{
public:
	double id, h, w;
	humman(int n, int high, int weight)
	{
		id = n;
		h = high / 100.0;
		w = weight;
	}
	double bmi()
	{
		return w / (h * h);
	}
};

int main()
{
	int n;
	while (true)
	{
		cin >> n;
		if (n == 0) break;
		humman nearest(-1, 1, 0xFFFFFF);
		for (int i = 0; i < n; i++)
		{
			int id, w, h;
			cin >> id >> w >> h;
			humman a(id, w, h);
			if (abs(22.0 - a.bmi()) < abs(22.0 - nearest.bmi()))
			{
				nearest = a;
			}
		}
		cout << nearest.id << endl;
	}
	return 0;
}