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

double bmi(double w, double m){
  return w / m / m;
}

int main(){
  int n;

  while(cin >> n, n){
    int ans = -1;
    double minDiff = 999999999;

    for(int i = 0; i < n; i++){
      int num, h, w;
      cin >> num >> h >> w;

      double b = fabs(bmi(w, h / 100.0) - 22.0);

      if(minDiff > b || minDiff == b && ans > num){
        ans = num;
        minDiff = b;
      }
    }

    cout << ans << endl;
  }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

map<long long int, int>mp;
int getans(const long long int n) {
	if (n < 0)assert(false);
	if (mp.find(n) != mp.end())return mp[n];
	else {
		int ans = n==1?0:n % 2 ? (1 + getans(3 * n + 1)) : (1 + getans(n / 2));
		return mp[n] = ans;
	}
}

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int ansid = 0;
		ld minn = 1e8;
		while (N--) {

			int p;
			ld h, w; cin >> p >> h >> w;
			ld bmi = w / (h*h / 10000);
			ld sa = abs(22 - bmi);
			if (minn > sa) {
				minn = sa;
				ansid = p;
			}
		}
		cout << ansid << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

typedef pair<int,double> T;

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		T ans(-1,inf);
		int num,w;
		double h;
		for(int i=0;i<n;i++){
			cin>>num>>h>>w;
			h/=100;
			double Sa=fabs(w/(h*h)-22);
			if(fabs(ans.second-Sa)<eps){
				if(ans.first>num) ans=T(num,Sa);
			}
			else if(ans.second>Sa) ans=T(num,Sa);
		}
		cout<<ans.first<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;


int main(){
	int n;
	int i,h,w;
	int an;
	double ab,bmi;
	while(cin>>n&&n>0){
		an=IMAX;
		ab=22.1;
		rep(j,n){
			cin>>i>>h>>w;
			bmi=(double)w*10000/h/h;
			//cout<<i<<" "<<bmi<<endl;
			if(fabs(bmi-22.0)<ab){
				an=i;
				ab=fabs(bmi-22.0);
			}
			if(fabs(bmi-22.0)==ab&&i<an){
				an=i;
			}
		}
		cout<<an<<endl;
	}
}

C++: #include <iostream>
#include <deque>
#include <cmath>
using namespace std;
int main()
{
	deque<int> m;
	deque<double> d, h, w;
	int n, i, t[3];
	double u;
	while (cin >> n && n)
	{
		u = 0;
		m.clear();
		h.clear();
		w.clear();
		d.clear();
		for (i = 0; i < n; i++)
		{
			cin >> t[0] >> t[1] >> t[2];
			m.push_back(t[0]);
			h.push_back((double)t[1]/100);
			w.push_back((double)t[2]);
			d.push_back(22.0 - w[i]/(h[i]*h[i]));
			if (i == 0) u = abs(d[0]);
			if (abs(d[i]) < u) u = abs(d[i]);
		}
		for (i = 0; i < n; i++)
		{
			if (u == abs(d[i]))
				cout << m[i] << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
 while(true){

      int n;

     
	  cin >> n ;
	  
      if(n==0)
         break;

	  double a, h , w;
      double BMI = 0;
      double H = 0;
      double max = 0;
	  double z ;
      int y=0;

      for(int i=0 ;i<n ;i++){
		     
            cin >> a >> h >> w;
            H = h / 100;
		
            BMI = w / H / H;

	
			z = 22 - BMI; 
            if(z < 0){
                z = z * (-1);
            }
		
			if(i == 0){
				max = z;
				y = a;
			}
			
			else if(max > z){
               
                 max = z;
				  y = a;
			}
	  }

			cout << y << endl;

 }
    
 return 0;
}

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

using namespace std;

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        int ans=-1;
        double t=1000000.0;
        for (int i = 0; i < n; ++i) {
            int p;
            double h,w;
            cin>>p>>h>>w;
            h=h/100.0;
            double tbmi=w/(h*h);
            if(t>abs(22.0-tbmi)){
                t=abs(22.0-tbmi);
                ans=p;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define N 1000000
#define STD_BMI 22.000
using namespace std;
struct Person{
	int id,h,w;
	double BMI;
	bool operator<(const Person &t)const{
		if( fabs(this->BMI-STD_BMI)<fabs(t.BMI-STD_BMI) ){
			return true;
		}else if( fabs(this->BMI-STD_BMI)==fabs(t.BMI-STD_BMI) ){
			return this->id < t.id;
		}
		return false;
	}
};
istream &operator>>(istream &is, Person &t){
	is>>t.id>>t.h>>t.w;
	t.BMI=t.w/((double)(t.h)*(t.h)/10000.0);
	return is;
}
int main(){
	while(true){
		int n;
		vector<Person> v;
		v.reserve(N);
		cin>>n;
		if(n==0)break;
		for(int i =0; i <n; ++i){
			Person t;
			cin>>t;
			v.push_back(t);
		}
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();++i){
			cout<<v[i].id<<" " <<v[i].BMI<<endl;
		}
		cout<<v[0].id<<endl;
	}
	return 0;
}