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>
using namespace std;

int n,ans2,id;
double ans,bmi,w,h;

double EPS = 1e10;

int main(){
  while(cin>>n&&n){
    ans=9999.9;
    for(int i=0;i<n;i++){
      cin>>id>>h>>w;
      bmi=abs( w/((h/100.0)*(h/100.0)) -22.0);
      if(bmi<ans){
	ans=bmi;ans2=id;
      }else if(bmi - EPS <ans && id<ans2){
	ans2=id;
      }
    }
    cout<<ans2<<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<double, 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(w/((h/100.0)*(h/100.0)) -22);
            v.push_back(a);
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n;
    while(cin>>n){
        int Aval = 999999999;
        int Anum = 999999999;
        
        if(n==0)break;
        
        rep(i,n){
            int num,h,w;
            cin>>num>>h>>w;
            double res = w/( (h/100.0)*(h/100.0) );
            if( abs(Aval-22)>abs(res-22) ||  (abs( abs(Aval-22) - abs(res-22) )<1e-9 && num<Anum)  ){
                Aval = res;
                Anum = num;
            }
        }
        cout<<Anum<<endl;
    }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int res = 0;
		double mi = INF;
		rep(i,n){
			int mem;
			double h,w;
			scanf("%d",&mem);
			scanf("%lf%lf",&h,&w);
			double x = fabs(22.0-(w/(h/100)/(h/100)));
			if(mi > x){
				mi = x;
				res = mem;
			}
			else if(mi == x){
				res = min(res,mem);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Human{
	int n,h,w;
	double bmi;
	void calcBMI(){
		bmi = (double)w/(h*0.01*h*0.01);
	}
	bool operator <(const Human &h)const{
		if(abs(22-bmi)==abs(22-h.bmi)) return n<h.n;
		return abs(22-bmi)<abs(22-h.bmi);
	}
};
Human h[1000000];

int main(){
	int N;
	while(cin>>N,N){
		for(int i=0;i<N;i++){
			cin>>h[i].n>>h[i].h>>h[i].w; h[i].calcBMI();
		}
		sort(h,h+N); printf("%d\n",h[0].n);
	}
	return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	int n;
	while(cin>>n,n!=0){
	vector<string> s(n);
	int k=0;
	double best=1000000;
	for(int i=0;i<n;i++){
		double a,b;
		cin>>s[i];
		cin>>a>>b;
		a=a*pow(10,-2);
		double bmi=double(b)/pow(a,2);
		
		if(abs(22-bmi)<best){
			k=i;
			best=abs(22-bmi);
		}
	}
	
	cout<<s[k]<<endl;
	
	}
	
	
}

C++: #include<iostream>
using namespace std;
int a,b,c,n,t[1000001],ansno;
double weight,height,bmi,bmi2,ansbmi;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    ansbmi=99999.9;
    ansno=9999999;
    for(int i=0;i<n;i++){
      cin>>a>>height>>weight;
      height/=100.0;
      bmi=weight/(height*height);
 
      bmi2=22.0-bmi;
       
      if(bmi2<0.0)bmi2*=-1.0;
      //cout<<bmi2<<endl;
      if(ansbmi>bmi2){
    ansbmi=bmi2;
    ansno=a;
      }
      if(ansbmi==bmi2&&ansno>a){
    ansbmi=bmi2;
    ansno=a;
      }
 
    }
    cout<<ansno<<endl;
     
  }
  return 0;
}

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

int main(){
	while(1){
		long n;
		double best=100;
		long ans;
		
		scanf(" %ld", &n);
		if(n==0) break;
		
		for(long i=0; i<n; ++i){
			long num;
			double h, w;
			scanf(" %ld %lf %lf", &num, &h, &w);	
		
			h/=100;
			double bmi=w/h/h;
			bmi-=22;
			if(bmi<0) bmi = -bmi;
		
			if(bmi<best){
				ans=num;
				best=bmi;	
			}
			else if(bmi==best){
				if(num<ans) ans=num;	
			}
		}
	
		printf("%ld\n", ans);
	}
	return 0;
}

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

int main(void){
    int n,num,h,w;
    
    while(1){
        double best = 22,tmp;
        int bn;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++){
            cin >> num >> h >> w;
            
            double nh = (double)h / 100;
            double BMI = (double)w / (nh*nh);
            if(!i){
                tmp = fabs(BMI-best);
                bn = num;
                continue;
            }
            
            if(tmp > fabs(BMI-best)){
                tmp = fabs(BMI-best);
                bn = num;
            }
        }
        cout << bn << endl;
    }

    return 0;
}