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;

int main(){
    int n;
    int id;
    double height, weight;
    double diff;
    double best;
    int ans;
    while(cin >> n, n){
        best = 1000;
        for(int i=0; i< n; i++){
            cin >> id >> height >> weight;
            diff = abs(22 - weight / pow(height/100, 2));

            if(diff < best){
                best = diff;
                ans = id;
            }
        }
        cout << ans << endl;
    }

}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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 <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		double minabs=INT_MAX;
		
		double len,wei,num,minnum;
		while(n--){
			cin>>num>>len>>wei;
			double dbmi=abs(22.0-wei/len/len*100*100);
			if(dbmi<minabs){
				minnum=num;
				minabs=dbmi;
			}
		}
		cout<<minnum<<endl;
	}
}

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

const double EPS = 1e-10;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int bestIndex;
    double bestBMI = 1e10;
    while (n--) {
      int i, h, w;
      cin >> i >> h >> w;
      
      double bmi = w / ((h/100.0)*(h/100.0));
      if (abs(22.0-bestBMI) - abs(22.0-bmi) > EPS) {
	bestBMI = bmi;
	bestIndex = i;
      } else if (abs(22.0-bmi) - abs(22.0-bestBMI) < EPS) {
	bestIndex = min(bestIndex, i);
      }
    }
    cout << bestIndex << endl;
  }
  return 0;
}

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

double f( double a )
{
    if( a > 0 )
        return a;
    else
        return -1 * a;
}

int main()
{
    int n, a[1000];
    double b[1000], c[1000];

    while( cin >> n )
    {
        if( n == 0 )
            break;

        double min = 100000;
        int j = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> a[i] >> b[i] >> c[i];
            if( min > f( 22 - c[i] / ( b[i] * b[i] / 10000 ) ) )
            {
                min = f( 22 - c[i] / ( b[i] * b[i] / 10000 ) );
                j = i;
            }
        }
        cout << a[j] << endl;
    }


    return 0;
}

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

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

int n;

int main()
{
	while( std::cin >> n, n )
	{
		P ans( 20001, 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<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef struct {
  int no;
  double BMI,abs;
}P;
int main(){
  int n,a,b,c;
  while(1){
    cin >> n;
    if(n==0)break;
    P temp;
    P sets[n];
    for(int i=0;i<n;i++){
      cin >> sets[i].no >> b >> c;

      sets[i].BMI=double(c)/((double)(b)/100.0*(double)(b)/100.0);
      if(sets[i].BMI<=22){
	sets[i].abs=22-sets[i].BMI;
      }else{
	sets[i].abs=sets[i].BMI-22;
      }
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(sets[j].abs<sets[j-1].abs){
	  temp=sets[j];
	  sets[j]=sets[j-1];
	  sets[j-1]=temp;
	}
      }
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(sets[j].abs==sets[j-1].abs && sets[j].no<sets[j-1].no){
	  temp=sets[j];
	  sets[j]=sets[j-1];
	  sets[j-1]=temp;
	}
      }
    }
    cout << sets[0].no << endl;
  }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		int p,num;
		double BMI,min=10000,h,w;
		for(int i=0;i<n;i++){
			cin>>p>>h>>w;
			BMI=w/((h/100)*(h/100));
			if(min>=abs(BMI-22)){
				if(min!=abs(BMI-22)){
					num=p;
				}
				min=abs(BMI-22);
			}
		}
		cout<<num<<endl;
	}
	return 0;
}

C++: //24
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int mi;
    double mb=1<<30;
    while(n--){
      int i;
      double h,w;
      cin>>i>>h>>w;
      double mbid=fabs(w*10000/h/h-22);
      if(mbid<mb||mbid==mb&&i<mi){
	mi=i;
	mb=mbid;
      }
    }
    cout<<mi<<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;

vector< pair<double, ll> > vp;

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

int main(){
	while (cin >> n&&n){
		REP(j, n){
			cin >> i >> h >> w;
			double a = fabs(BMI(h, w) - 22.0);
			vp.push_back(pair<double, ll>(a, i));
			//if (a < -EPS){
			//	bmi = BMI(h, w);
			//	index = i;
			//}
			//if (fabs(a) < EPS){
			//	index = min(i, index);
			//}
		}
		sort(ALL(vp));
		cout << vp[0].second << endl;
		vp.clear();
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[1000],x,i;
	double h[1000],w[1000],y;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++) {
			scanf("%d %lf %lf",&p[i],&h[i],&w[i]);
			h[i]=h[i]/100;
			h[i]=w[i]/(h[i]*h[i]);
			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;
}