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;

const double inf = 1e10;

double BMI(double w, double h) {
  return w / pow(h, 2);
}

int main() {
  int n;
  while(cin >> n && n) {
    pair<double,int> p(inf, 0);
    for(int i = 0; i < n; ++i) {
      int id;
      double h, w;
      cin >> id >> h >> w;
      h /= 100.0;
      p = min(p, make_pair(abs(22.0-BMI(w,h)), id));
    }
    cout << p.second << endl;
  }
  return 0;
}

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

using namespace std;

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

        double diff = 999999999.9;
        int least = -1;
        for( int i=0; i<n; ++i ) {
            int i, h, w;

            cin >> i >> h >> w;

            double const bmi = static_cast<double>( w ) / pow( static_cast<double>( h ) / 100.0, 2 );

            double const d = abs( 22.0 - bmi );
            if ( d < diff ) {
                diff = d;
                least = i;
            }
        }

        cout << least << endl;
    }
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef map<double, int> MAPDI;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMAPIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

double BMI(int h, int w){
	// h/100 ではダメ, h/100.0 って書く.
	double ret = w / pow(h / 100.0, 2.0);
	return ret;
}

void solve(map<double, int> &bmiList){
	foreach_it(MAPDI, it, bmiList){
		cout << (*it).second << endl;
		break;
	}
}

int main(){
	fastIO;
	int n = 0;
	while (cin >> n,n){
		int i = 0, h = 0, w = 0;
		map<double, int> bmiList;
		while (n--){
			cin >> i >> h >> w;
			bmiList.insert(MP(abs(22.00 - BMI(h, w)), i));
		}
		solve(bmiList);
	}
	return 0;
}

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

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

const int INF = 1 << 30;

int n;

int main()
{
	while( std::cin >> n, n )
	{
		P ans( INF, INF );
		
		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 <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while( cin >> n && n ){
		vector< pair< double, int > > list1;
		vector< pair< double, int > > list2;
		for( int i = 0; i < n; ++i ){
			int id, h, w;
			cin >> id >> h >> w;
			double hh = static_cast< double >( h ) / 100;
			double bmi = w / ( hh * hh );
			if( bmi >= 22.0 ){
				list1.push_back( make_pair( bmi, id ) );
			}else{
				list2.push_back( make_pair( bmi, id ) );
			}
		}
		sort( list1.begin(), list1.end() );
		sort( list2.begin(), list2.end() );
		pair< double, int > high, low;
		if( !list1.empty() ){
			high = list1[ 0 ];
		}
		if( !list2.empty() ){
			low = list2[ list2.size() - 1 ];
			vector< pair < double, int > >::reverse_iterator itr = list2.rbegin();
			while( itr != list2.rend() ){
				if( itr->first < low.first ){
					break;
				}
				low = *itr;
				++itr;
			}
		}
		int result = 0;
		if( high.first - 22.0 < 22.0 - low.first ){
			result = high.second;
		}else{
			result = low.second;
		}
		cout << result << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Human{
	int n,h,w;
	double bmi;
	void calcBMI(){
		bmi = (double)w/(h*0.01*h*0.01);
	}
	bool operator <(const Human &h)const{
		if(abs(22-bmi)==abs(22-h.bmi)) return n<h.n;
		return abs(22-bmi)<abs(22-h.bmi);
	}
};
Human h[1000000];

int main(){
	int N;
	while(cin>>N){
		for(int i=0;i<N;i++){
			cin>>h[i].n>>h[i].h>>h[i].w; h[i].calcBMI();
		}
		sort(h,h+N); printf("%d\n",h[0].n);
	}
	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=0;
for(int k=0;k<n;k++){
	cin>>num>>ta>>omo;
	bmi=omo/(ta*ta);
	if(bmi-22<0){
		sa=22-bmi;
	}
	else{
		sa=bmi-22;
	}
	if(sa<max){
		best=num;
		max=sa;
	}
}
cout<<best<<endl;
}
	return 0;
}