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 <cmath>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<double,int> P;

int main() {
  int n;
  vector<P> V;
  P temp;
  while(cin >> n) {
    V.clear();
    if(n==0) break;
    int k;
    double h,w;
    for(int i=0;i<n;i++) {
      cin >> k >> h >> w;
      temp.first = abs(w / ((h/100)*(h/100)) - 22.0);
      temp.second = k;
      V.push_back(temp);
    }

    sort(V.begin(),V.end());
    temp = V[0];
    cout << temp.second << endl;
  }
}

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

#define ABS(X) ((X)<0?-(X):(X))
typedef pair<double, int> Subj;

int main(void){  
  int n;
  
  while (cin >> n){
    vector<Subj> v;
    for (int i=0; i<n; i++){
      int id;
      double h,w,bmi;
      cin >> id >> h >> w;
      h /= 100;
      bmi = w/(h*h);
      v.push_back(make_pair(ABS(bmi-22), id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		double mindif;
		vector<int> ids,hs,ws;
		for(int i=0,id,h,w;i<n;++i){
			cin>>id>>h>>w;
			ids.push_back(id);
			hs.push_back(h);
			ws.push_back(w);
		}
		int ans;
		for(int i=n-1;i>=0;--i){
			double bmi=(double)ws[i]*10000/(double)(hs[i]*hs[i]);
			if(i==n-1||mindif>abs(22.0-bmi)){
				mindif=abs(22.0-bmi);
				ans=ids[i];
			}
		}
		cout<<ans<<"\n";
	}
}

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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int num[n];
      int data[n];
      int min=1000000;
      int min_num;
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin>>num[i]>>a>>b;
	  data[i]=b/((a/100.0)*(a/100.0));
	  //cout<<data[i]<<endl;
	  data[i]-=22;
	  if(data[i]<0)
	    data[i]=-data[i];
	  //	  cout<<data[i]<<endl;
	  if(data[i]<min||data[i]==min&&num[i]<num[min_num])
	    {
	      min=data[i];
	      min_num=i;
	    }
	}
      cout<<num[min_num]<<endl;
    }
}

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

int main() {
	
	double ideal = 22;
	double min = DBL_MAX;
	int minId=1000000;
	
	int n;
	
	float id;
	float hght;
	float wght;
	
	double BMI;
	
	
	while(cin>>n,n){
		
		min = DBL_MAX;
		
		for(int i=0;i<n;++i){
			cin >> id >> hght >> wght;
			BMI = wght / (hght*hght) * 10000;
			
			if(fabs(BMI-ideal) < min){min=fabs(BMI-ideal);minId=id;}
			else if(fabs(BMI-ideal) == min){
				if(id<minId){
					min=fabs(BMI-ideal);
					minId=id;
				}
			}
		}
		cout << minId << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

double bmi(double a, double b){
    return a / b / b;
}

int main(){
    int n, num;
    while(cin >> n, n){
        double m, kg;
        double ans = 2 << 24, ansmbi = 2 << 24;
        rep(i, n){
            cin >> num >> m >> kg;
            double re = fabs(bmi(kg, m / 100) - 22);
            if(ansmbi > re || (ansmbi == re && ans > num)){
                ansmbi = re;
                ans = num;
            }
        }
        cout << ans << endl;
    }
}

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

double num[1000000],h[1000000],w[1000000];
int n;

int main(){
	while(true){
		int ans = 0;
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			cin >> num[i] >> h[i] >> w[i];
			h[i] /= 100;
			h[i] *= h[i];
			w[i] /= h[i];
			w[i] -= 22;
			if(w[i] < 0)
				w[i] *= -1;
			if(w[ans] > w[i]){
				ans = i;
			}else if(w[ans] == w[i] && num[ans] > num[i])
				ans = i;
		}
		cout << num[ans] << endl;
	}
}

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

class Fraction {
public:
    long long a, b;
    Fraction(int a, int b) : a(a), b(b) {};
    Fraction operator-(const Fraction f) {
        return Fraction(a * f.b - f.a * b, b * f.b);
    }
    bool operator==(const Fraction f) {
        return a * f.b == f.a * b;
    }
    bool operator<(const Fraction f) {
        return a * f.b < f.a * b;
    }
};

Fraction abs(Fraction f) {
    f.a = abs(f.a);
    f.b = abs(f.b);
    return f;
}

int main() {
    int n;
    while (cin >> n, n) {
        int best = -1, i, h, w;
        Fraction mn(10000, 1);
        for (int k=0; k<n; ++k) {
            cin >> i >> h >> w;
            Fraction dif = abs(Fraction(22, 1) - Fraction(w*10000, h*h));
            if (dif < mn || (dif == mn && i < best)) {
                mn = dif;
                best = i;
            }
        }
        cout << best << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cmath>
int main() 
{
    int i,h,w,n;
    while (scanf("%d",&n)&&n!=0) {
        int res=0;
        double mindiff=1000000.0;
        for (int j=0; j<n; j++) {
            scanf("%d %d %d",&i,&h,&w);
            double diff=22.0-(double)w/(h*h)*10000;
            if (diff<0) diff*=-1;
            if (diff<mindiff) {
                mindiff=diff;
                res=i;
            }
        }
        printf("%d\n",res);
    }
}

C++: #include <iostream>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
typedef pair<double,int> P;

int main() {
  int n;
  vector<P> V;
  P temp;
  while(cin >> n) {
    V.clear();
    if(n==0) break;
    int k;
    double h,w;
    for(int i=0;i<n;i++) {
      cin >> k >> h >> w;
      temp.first = abs(w / ((h/100)*(h/100)) - 22.0);
      temp.second = k;
      V.push_back(temp);
    }

    sort(V.begin(),V.end());
    temp = V[0];
    cout << temp.second << endl;
  }
}