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>
using namespace std;


//対象者構造体
typedef struct struct_data
{
	int bangou;
	int sintyou;
	int taizyuu;
}S_data;

//----- 最大値格納関数 -----//
void f_max(S_data * , S_data *);

//----- 構造体初期化関数 -----//
void f_syokika(S_data *);

int main(void)
{
	//入力数
	int n = 0;
	//人
	S_data s_data = {0};
	S_data s_max = {0};

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			return 0;
		}

		//初期化
		f_syokika(&s_max);

		for (int i = 0; i < n; i++)
		{
			cin >> s_data.bangou >> s_data.sintyou >> s_data.taizyuu;
			f_max(&s_max , &s_data);
		}

		//出力
		cout << s_max.bangou << endl;
	}

	return 0;
}



//*****----- 最大値格納関数 -----*****//

void f_max(S_data *ptr_max , S_data *ptr_data)
{
	//BMPの近いほう
	//int max_sa = 22;
	//int data_sa = 22;
	double max_sa = 22;
	double data_sa = 22;

	double double_max = 0;
	if (ptr_max->bangou != 0 && ptr_max->sintyou != 0 && ptr_max->taizyuu != 0)
	{
		double_max = (double)ptr_max->sintyou / 100;

		max_sa -= ptr_max->taizyuu / (double_max * double_max);

		if (max_sa < 0)
		{
			max_sa *= -1;
		}
	}
	double double_data = 0;
	double_data = (double)ptr_data->sintyou / 100;
	data_sa -= (double)ptr_data->taizyuu / (double_data * double_data);

	if (data_sa < 0)
	{
		data_sa *= -1;
	}

	/*if (ptr_max->bangou != 0 && ptr_max->sintyou != 0 && ptr_max->taizyuu != 0)
	{
		max_sa -= ((double)ptr_max->taizyuu / ((double)ptr_max->sintyou * (double)ptr_max->sintyou / 10000));
		if (max_sa < 0)
		{
			max_sa *= -1;
		}
	}

	data_sa -= ((double)ptr_data->taizyuu / ((double)ptr_data->sintyou * (double)ptr_data->sintyou / 10000));
	if (data_sa < 0)
	{
		data_sa *= -1;
	}*/

	//現在の方が差が大きいのなら
	if (max_sa > data_sa)
	{
		*ptr_max = *ptr_data;
	}
}



//*****----- 構造体初期化関数 -----*****//

void f_syokika(S_data *ptr_max)
{
	ptr_max->bangou = 0;
	ptr_max->sintyou = 0;
	ptr_max->taizyuu = 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int ans;
    int n;
    while(true){
        cin >> n;
        if(n == 0) break;
        double tmpans = 1000000;
        for(int i = 0;i < n;i++){
            int p;
            double h,w;
            cin >> p >> h >> w;
            h /= 100.0;
            double tmpbmi =  w / ( h*h);
        //    cout <<  p << ":" << tmpbmi << endl;
            if(max(22.0-tmpbmi,tmpbmi-22.0) < tmpans){
                tmpans = max(22.0-tmpbmi,tmpbmi-22.0);
                ans = p;
            }
        }
        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define N 1000000
#define STD_BMI 22.000
#define EPS 1.0e-10
using namespace std;
struct Person{
	int id,h,w;
	double BMI;
	bool operator<(const Person &t)const{
		if( fabs(this->BMI-STD_BMI)<fabs(t.BMI-STD_BMI) ){
			return true;
		}else if( fabs( fabs(this->BMI-STD_BMI) - fabs(t.BMI-STD_BMI) ) < EPS ){
			return this->id < t.id;
		}
		return false;
	}
};
istream &operator>>(istream &is, Person &t){
	is>>t.id>>t.h>>t.w;
	t.BMI=t.w/((double)(t.h)*(t.h)/10000.0);
	return is;
}
int main(){
	while(true){
		int n;
		vector<Person> v;
		v.reserve(N);
		cin>>n;
		if(n==0)break;
		for(int i =0; i <n; ++i){
			Person t;
			cin>>t;
			v.push_back(t);
		}
		sort(v.begin(),v.end());
		cout<<v[0].id<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,h,w;
	int j;
	double best;
	double bmi;
	int a,sa;
	
	scanf("%d",&n);
	best=22.0;
	while(n!=0){
		sa=99999;
		for(j=0;j<n;j++){
			scanf("%d %d %d",&i,&h,&w);
			bmi=(double)w/(h*h)*10000;
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n;
    while(cin>>n){
        int Aval = 999999999;
        int Anum = 999999999;
        
        if(n==0)break;
        
        rep(i,n){
            int num,h,w;
            cin>>num>>h>>w;
            double res = w/( (h/100.0)*(h/100.0) );
            if( abs(Aval-22)>abs(res-22)-1e-9 ||  (abs( abs(Aval-22) - abs(res-22) )<1e-9 && num<Anum)  ){
                Aval = res;
                Anum = num;
            }
        }
        cout<<Anum<<endl;
    }
}

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

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

using namespace std;
typedef pair<int, double> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		double min_BMI = 99999999;
		vector<P> data;
		for(int i = 0; i < n; ++i)
		{
			int a;
			cin >> a;
			double h, w;
			cin >> h >> w;
			double BMI = 10000 * w / (h * h);
			data.push_back(P(a, fabs(22 - BMI)));
			if(fabs(22 - BMI) < min_BMI)
			{
				min_BMI = fabs(22 - BMI);
			}
		}
		int min_number = 999999999;
		for(int i = 0; i < n; ++i)
		{
			if(data[i].second == min_BMI)
			{
				if(data[i].first < min_number)
				{
					min_number = data[i].first;
				}
			}
		}
		cout << min_number << endl;
	}
}

int main()
{
	solve();
	return(0);
}