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<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/(((double)h/100)*((double)h/100));
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
//			printf("%lf\n",bmi);
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
			else if(sa==bmi && a>i){
				a=i;
			}	
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  while(1){

    int n;

    cin >> n;

    if(n == 0) break;

    int min = 100000000;
    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(min > bmi[i]){
	minnum = num;
	min = bmi[i];
      }
    }

    cout << minnum << endl;
  }


  return 0;

}

C++: #include <iostream>
#include <utility>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<int, int>
int main(){
    int n, h, w;
    pint a;
    while(cin >> n, n) {
        vector<pint> v;
        rep(i,n) {
            cin >> a.second;
            cin >> h >> w;
            a.first = abs(h * h * 22 - w * 10000);
            v.push_back(a);
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
        rep2(i,1,n) {
			if(v[i].first != v[0].first) break;
            cout << v[i].second << endl;
        }
    }
    return 0;
}

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

#define BESTBMI 22
#define MAX 10000

class CDATA {
public:
  int stnum;
  double hei, wei;
  double bmi;
  
  void setBMI() {
    bmi = wei/(hei*hei);
  }
  
  bool operator< (const CDATA &t) const {
    if(abs(22-bmi)==abs(22-t.bmi)) return stnum<t.stnum;
    else return abs(22-bmi) < abs(22-t.bmi);
  }
};

int main() {
  int n;
  double h;
  CDATA person[MAX]; 
  
  while(cin>>n, n) {
    for(int i=0; i<n; i++) {
      cin>>person[i].stnum>>h>>person[i].wei;
      person[i].hei=h/100;
      person[i].setBMI();
    }
    
    stable_sort(person, person+n);
    
    cout<<person[0].stnum<<endl;
    
  }

  return 0;
}

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

int main(){
	int n;
	while( cin >> n , n ){
		double BMI[1000001];
		for(int i=0 ; i < 1000001 ; i++ ){
			BMI[i] = -1;
		}

		for(int i=0 ; i < n ; i++ ){
			int id,h,w;
			cin >> id >> h >> w;
			BMI[id] = fabs( 22.0 - (double) w / ( (h/100.0)*(h/100.0) ) );
		}
		double m = 1000.0;
		for(int i=0 ; i < 1000001 ; i++ ){
			if( BMI[i] != -1 )
				m = min( m , BMI[i] );
		}
		for(int i=0 ; i < 1000001 ; i++ ){
			if( BMI[i] == m ){
				cout << i << endl;
				break;
			}
		}
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		int a;
		double b,c;
		int i;
		int res;
		double resbmi=0;
		double bmi;
		for(i=0;i<n;i++){
			cin>>a>>b>>c;
			bmi=c*10000/b/b;
			if(fabs(bmi-22)<fabs(resbmi-22)){
				res=a;
				resbmi=bmi;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    while(true){
      int n;
      cin >> n;
      if(n == 0){
        break;
      }
      int ans=-1;
      double mi=1e9;
      double ideal = 22.0;
      for(int i=0; i<n; i++){
        int p;
        double h, w;
        cin >> p >> h >> w;
        h /= 100;
        double bmi;
        bmi = w/(h*h);
        double riso;
        riso = abs(bmi-22.0);
        if(mi >= riso){
          mi = riso;
          ans = p;
        }
      }
      cout << ans << endl;
    }
  return 0;
}