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 <algorithm>

using namespace std;

double abs(double a){
    if(a>0)return a;
    else return -a;
}
double bmi(double height,double weight){
    return 10000 * weight / (height*height);
}

int solve(int n){
    float ma = -1;
    int mai = -1;
    for(int i=0;i<n;i++){
        int a;
        double h,w;
        cin >> a >> h >> w;
        double b = bmi(h,w);
        if((abs(ma-22) == abs(b-22)) && a < mai){ mai = a; ma = b;}
        if(abs(ma-22) > abs(b-22)){ mai = a;ma = b;}
    }
    return mai;
}

int main(){
    int n;
    while(cin >> n && n != 0){
        cout << solve(n) << endl;
    }
}

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

int main()
{
	int n;
	while( cin >> n && n ){
		vector< pair< double, int > > list1;
		vector< pair< double, int > > list2;
		for( int i = 0; i < n; ++i ){
			int id, h, w;
			cin >> id >> h >> w;
			double hh = static_cast< double >( h ) / 100;
			double bmi = w / ( hh * hh );
			if( bmi >= 22.0 ){
				list1.push_back( make_pair( bmi, id ) );
			}else{
				list2.push_back( make_pair( bmi, id ) );
			}
		}
		sort( list1.begin(), list1.end() );
		sort( list2.begin(), list2.end() );
		pair< double, int > high, low;
		if( !list1.empty() ){
			high = list1[ 0 ];
		}
		if( !list2.empty() ){
			low = list2[ list2.size() - 1 ];
			vector< pair < double, int > >::reverse_iterator itr = list2.rbegin();
			while( itr != list2.rend() ){
				if( itr->first < low.first ){
					break;
				}
				low = *itr;
				++itr;
			}
		}
		int result = 0;
		if( list1.empty() ){
			result = low.second;
		}else if( list2.empty() ){
			result = high.second;
		}else if( high.first - 22.0 < 22.0 - low.first ){
			result = high.second;
		}else{
			result = low.second;
		}
		cout << result << endl;
	}

	return 0;
}

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;
            }
        }
        cout << p[mini] << endl;
    }

    return 0;
}

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

#define ABS(X) ((X)<0?-(X):(X))
typedef pair<double, int> Subj;

int main(void){  
  int n;
  
  while (cin >> n){
    if (n==0) break;
    vector<Subj> v;
    for (int i=0; i<n; i++){
      int id;
      double h,w,bmi;
      cin >> id >> h >> w;
      h /= 100;
      bmi = w/(h*h);
      v.push_back(make_pair(ABS(bmi-22), id));
    }
    sort(v.begin(), v.end());
    cout << v[0].second << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int n,i,h,w,ans=0;
		double bmi,d=2000001;
		cin>>n;
		if(n==0) break;
		rep(j,0,n){
			cin>>i>>h>>w;
			bmi=(double)w/(h*h)*10000;
			//o(bmi);
			if(abs(22-bmi)<d){
				d=abs(22-bmi); ans=i;
			}if(abs(22-bmi)==d) ans=min(i,ans);
		}
		o(ans);
	}
}

C++: #include <iostream>
#include <map>
#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 pdi pair<double, int>
int main(){
	int n, h, w;
	pdi a;
	while(cin >> n, n) {
		vector<pdi> v;
		rep(i,n) {
			cin >> a.second;
			cin >> h >> w;
			a.first = abs(w / ((h/100.0) * (h/100.0)) - 22);
			v.push_back(a);
		}
		sort(v.begin(), v.end());
		rep(i,v.size()) 
		cout << v[i].first << " " << v[i].second << endl;

		cout << v[0].second << endl;
		int i = 1;
		while(v[i].first == v[i+1].first) {
			cout << v[i].second << endl;
			i++;
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <map>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int main()
{
	while (true) {
		int n; scanf("%d", &n); if (n == 0) break;
		pair<double, int> best = mp(99999999, 99999999);
		rep(i, n) {
			int k, h, w; scanf("%d%d%d", &k, &h, &w);
			double bmi = 10000 * w / ((double)h * h);
			pair<double, int> t = mp(fabs(22.0 - bmi), k);
			if (best > t) best = t;
		}
		printf("%d\n", best.second);
	}
	return 0;
}