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 <algorithm>
#include <vector>
#include <map>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n && n){
        int a1 = 1000000000;
        double a2 = 10000000;
        vector<pair<double,int>> v(n);
        rep(i,n){
            int x,h,w;
            cin>>x>>h>>w;
            double bmi = 1. * w/h/h*10000;
            if(abs(a2-22)>abs(bmi-22) || (abs(a2-22)==abs(bmi-22) && a1>x)){
                a1 = x;
                a2 = bmi;
            }
        }
        cout << a1 << 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-10000*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>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
	int n;
	int id;
	double height, weight;
	double defferencial;
	double bestBody;
	int ans;
	while(cin >> n, n){
		bestBody = 1000;
		for(int i=0; i< n; i++){
			cin >> id >> height >> weight;
			defferencial = abs(22 - weight / pow(height/100, 2));

			if(defferencial < bestBody){
				bestBody = defferencial;
				ans = id;
			}
		}
		cout << ans << endl;
	}

}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
long n,i,m,p,h,w;
double b;
while(cin>>n){
if(n==0)break;
cin>>m>>h>>w;
b=fabs(10000.*w/h/h-22);p=m;
for(i=1;i<n;i++){
cin>>m>>h>>w;
if(b>fabs(10000.*w/h/h-22)||
b==fabs(10000.*w/h/h-22)&&p>m){b=fabs(10000.*w/h/h-22);p=m;}
}
cout<<p<<endl;
}
return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int ansp=0;
    double ansbmi=10000;
    int p;
    double h,w;
    rep(i,n){
      cin>>p>>h>>w;
      h/=100;
      if(ansbmi>fabs(22-w/h/h)){
        ansp=p;
        ansbmi=fabs(22-w/h/h);
      }
    }
    cout<<ansp<<endl;
  }
}

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 > abs(bmi - 22)) {
                min = abs(bmi - 22);
                mini = i;
            } else if (min == abs(bmi - 22)) {
                if (mini > i) {
                    mini = i;
                }
            }
        }
        cout << p[mini] << endl;
    }

    return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >>n, n)
	{
		int index = 999999999;
		double bmi = 999999999;
		while(n--)
		{
			int i, h, w;
			cin >> i >> h >> w;
			double data = (double)w * 100 * 100 / h / h;
			if(fabs(22 - data) == bmi && index > i)
			{
				index = i;
			}
			else if(fabs(22 - data) < bmi)
			{
				bmi = fabs(22 - data);
				index = i;
			}
		}
		cout << index << endl;
	}
}

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

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

int solve() {
  int N; cin >> N;
  if(N == 0) return 1;

  double ideal = 22.0;
  double mi = 1e9; int id = -1;
  for(int i=0; i<N; i++) {
    int p; double h, w; cin >> p >> h >> w;
    h /= 100.0;
    double bmi = w / (h * h);

    double sub = fabs(ideal - bmi);
    if(sub < mi) {
      mi = sub;
      id = p;
    }
  }
  cout << id << endl;
  return 0;
}

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