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 <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);
    while (true) {
        double min = 1 << 21;
        int mini = 0;

        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<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){

	int n, id, h, w, id_best;
	double ideal, best, bmi, eps;

	ideal = 22.0;
	eps = pow(0.1, 5);
	
	while(cin >> n){
		if(n == 0) break;
		
		id_best = 1000000;
		best = 1000.0;
	
		for(int i=0; i<n; i++){
			cin >> id >> h >> w;
			bmi = w / pow(0.01 * h, 2);
			if(best > abs(ideal - bmi) || (best - abs(ideal - bmi) < eps && id_best > id)){
				best = abs(ideal - bmi);
				id_best = id;
			}
		}
	
		cout << id_best << endl;
	}

	return 0;

}

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

int main(){
  int n;
  int id,h,w;
  double b,bb;
  int bid;
  double t1,t2;

  while(1){
    cin >> n;
    if(!n)break;


    bb = 200000001.0;
    bid = 1000001;
    for(int i=0;i<n;i++){
      cin >> id >> h >> w;
      b = (double)w / ( (double)h/100 * (double)h/100 );
      t1 = abs(22.0-b);
      t2 = abs(22.0-bb);
      if( abs(t1-t2) < 1e-10){
	if(id<bid){
	  bb = b;
	  bid = id;
	}
      }else if(t1 < t2){
	bb = b;
	bid = id;
      }
    }
    cout << bid << endl;
  }
}

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

using namespace std;

int main() {

  int n;
  int i,h,w;

  double bmi;
  int id;

  while(cin >> n) {

    if(n==0) break;

    bmi=100.0;

    for(int idx=0;idx<n;idx++) {

      cin >> i >> h >> w;

      if(fabs((double)w/((double)(h*h)/10000.0)-22.0)<fabs(bmi-22.0)) {

	id=i;

	bmi=(double)w/((double)(h*h)/10000.0);

      }

      else if(fabs((double)w/((double)(h*h)/10000.0)-22.0)==fabs(bmi-22.0)) {

	if(id>i) id=i;

	bmi=(double)w/((double)(h*h)/10000.0);

      }

      //cout << bmi << endl;

    }

    cout << id << endl;

  }

}

C++: #include<iostream>

using namespace std;

int main(){

  while(1){

    int n;

    cin >> n;

    if(n == 0) break;

    double 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];
      }

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

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

}

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=100000;
		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<stdio.h>
double abs(double t){
	if(t<0)return -t;
	return t;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		double dist=100000;
		int id;
		for(int i=0;i<a;i++){
			int b;
			double c,d;
			scanf("%d%lf%lf",&b,&c,&d);
			if(abs(d*10000/c/c-22)<dist){
				dist=abs(d*10000/c/c-22);
				id=b;
			}
			//printf("%lf",dist);
		}
		printf("%d\n",id);
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,h,w;
	int j;
	int a,best;
	double bmi;
	int sa;
	
	scanf("%d",&n);
	best=22;
	while(n!=0){
		sa=99999;
		for(j=0;j<n;j++){
			scanf("%d %d %d",&i,&h,&w);
			bmi=(double)w/(h*h)*10000;
			printf("%lf\n",bmi);
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}