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;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int num[n];
      double data[n];
      double min=1000000;
      int min_num;
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin>>num[i]>>a>>b;
	  data[i]=(double)b/((a/100.0)*(a/100.0));
	  ///  cout<<data[i]<<endl;
	  data[i]-=22;
	  data[i]=max(data[i],-data[i]);
	  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>
#define ABS(n) (((n)>0)?(n):-(n))
using namespace std;
int main()
{
  int n,i,h,w,d,b,m;
  for(;;){
    cin >> n;
    if(n==0) break;
    d = 0x1fffffff;
    while(n--){
      cin >> i >> h >> w;
      b = w*10000000 / h / h;
      if(d > ABS(22000 - b)){
	d = ABS(22000 - b);
	m = i;
      }
    }
    cout << m << endl;
  }
  return 0;
}

C++: //include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//typedef
//-------------------------------------------
typedef long long ll;
int p[1001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double min = 1 << 21;
    int mini = 0;
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;

        int h, w;
        REP(i, n) {
            cin >> p[i] >> h >> w;
            double hd = ((double) h ) / 100;
            double bmi = (double)w / (hd * hd);
            if (min > fabs(bmi - 22.0)) {
                min = fabs(bmi - 22.0);
                mini = i;
            } else if (min == fabs(bmi - 22.0)) {
                if (mini > i) {
                    mini = i;
                }
            }
        }
        cout << p[mini] << endl;
    }
    return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<double,double> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
    vector<pii>v;
    rep(i,n){
        pii ujimatsu; int gotiusa;
        cin>>gotiusa>>ujimatsu.first>>ujimatsu.second;
        v.push_back(pii(abs(22-(((double)ujimatsu.second/(pow((double)ujimatsu.first/100,2))))),gotiusa));
    }
    sort(all(v));
    cout<<v[0].second<<endl;}
}

C++: // AOJ 0159
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		vector < pair <double, int> > d;
		double h, w;
		int id;
		for (int i = 0; i < n; i++){
			cin >> id >> h >> w;
			h /= 100.0;
			double bmi = w / (h * h);
			d.push_back(make_pair(abs(bmi - 22.0), id));
		}
		sort(d.begin(), d.end());
		// for (int i = 0; i < n; i++){
		// 	cout << d[i].first << " " << d[i].second << endl;
		// }
		cout << d[0].second << endl;
	}

	return 0;
}

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

using namespace std;
 
int main()
{
    int n, num, h, w;
     
    while (1) {
        double best = 22, tmp;
        int bn;
         
        cin >> n;
        if(!n) break;
         
        for (int i = 0; i < n; i++) {
            cin >> num >> h >> w;
             
            double nh = (double)h / 100;
            double BMI = (double)w / (nh*nh);
            if (!i) {
                tmp = fabs(BMI-best);
                bn = num;
                continue;
            }
            if (tmp > fabs(BMI-best)) {
                tmp = fabs(BMI-best);
                bn = num;
            }
        }
        cout << bn << endl;
    }
    return 0;
}