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 <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<int, int> 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++: #include<iostream>
using namespace std;
int h, w, maxid, n, b; double maxn = 1000000000.00;
int main() {
	while (true) {
		cin >> n;
		maxn = 1000000000.00;
		for (int i = 0; i < n; i++){
			cin >> b >> h >> w;
			if (maxn >= 10000.00*w / (h*h) - 22.00) {
				maxn = 10000.00*w / (h*h) - 22.00;
				maxid = b;
			}
		}
		cout << maxid << endl;
	}
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n;
	while (cin >> n&&n)
	{
		double a=999999999999999.0; int ans = 0;
		FOR(i, n)
		{
			INT(id);
			double h, w;
			cin >> h >> w;
			h /= 100;
			double bmi = w / h / h;
			if (a > fabs(22.0 - bmi))
			{
				a = fabs(22.0 - bmi);
				ans = id;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,m;
double h,w;

int main(){
	while(cin>>n){
		if(!n)return 0;
		int mm=0;
		double md;
		while(n--){
			cin>>m>>h>>w;
			double d=fabs(w*10000.0/h/h-22.0);
			if(!mm||d<md||d==md&&m<mm){md=d;mm=m;}
		}
		cout<<mm<<endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<double, int> > bmi(n);
        for(int i=0; i<n; ++i){
            int h, w;
            cin >> bmi[i].second >> h >> w;
            bmi[i].first = abs(22 - w/pow(h/100.0, 2.0));
        }
        cout << min_element(bmi.begin(), bmi.end())->second << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int n;
  while(cin >> n, n) {
    int mi = INF;
    int res;
    REP(i,n) {
      int a;
      double h, w;
      cin >> a >> h >> w;

      int hoge = abs(22.0-10000.0*w/(h*h));
      if (mi >= hoge) {
        if (mi == hoge) {
          if (a < res)
            res = a;
        } else {
          mi = hoge;
          res = a;
        }
      }
    }
    cout << res << endl;
  }
}

C++: #include<iostream>

using namespace std;

int main(){

  while(1){

    int n;

    cin >> n;

    if(n == 0) break;

    int min;
    int minnum;
    double bmi[n];

    for(int i = 0; i < n; i++){
      int num;
      double tall, wei;

      cin >> num >> tall >> wei;

      bmi[i] = wei / (tall / 100) / (tall / 100);

      bmi[i] -=22;

      if(bmi[i] < 0) bmi[i] *= -1;

      if(i == 0){
	minnum = num;
	min = bmi[i];
      }
 
      if(min > bmi[i]){
	minnum = num;
	min = bmi[i];
      }else if(min == bmi[i]){
	if(minnum > num) minnum = num;
      }
    }

    cout << minnum << endl;
  }
  return 0;

}

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

main(){
    int n, i, ans;
    double minv, bmi, w, h;
    while( cin >> n && n ){
	minv = (1<<21);
	for ( int j = 0; j < n; j++ ){
	    cin >> i >> h >> w;
	    h *= 0.01;
	    bmi = w/(h*h);
	    if ( fabs(22-bmi) < minv ){
		minv = fabs(22-bmi);
		ans = i;
	    }
	}
	cout << ans << endl;
    }
}