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>
#include <cmath>

using namespace std;

int main(void){

  double n,h,w,i;
  double BMI;

  while( cin >> n , n ){

    double risou = 9999999;
    int num = 9999999;

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

      BMI = w / pow( h/100 , 2 );

      if( abs(22 - BMI) <= abs(22 - risou) ){
	if( abs(22 - BMI) == abs(22 - risou) ){
	  if( i < num ) num = i;
	  continue;
	}
	risou = BMI;
	num = i;
      }
    }
    cout << num << endl;

  }
  return 0;
}

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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int num[n];
      double data[n];
      int min=1000000;
      int min_num;
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin>>num[i]>>a>>b;
	  data[i]=(double)b/((a/100.0)*(a/100.0));
	  ///  cout<<data[i]<<endl;
	  data[i]-=22;
	  data[i]=max(data[i],-data[i]);
	  if(data[i]<min||data[i]==min&&num[i]<num[min_num])
	    {
	      min=data[i];
	      min_num=i;
	    }
	}
      cout<<num[min_num]<<endl;
    }
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[1000],x,i;
	double h[1000],w[1000],y;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++) {
			scanf("%d %lf %lf",&p[i],&h[i],&w[i]);
			h[i]=h[i]/100;
			h[i]=w[i]/(h[i]*h[i]);
		
//			if(h[i]<0)  h[i]=h[i]*-1;
			
			h[i]=h[i]-22;
			if(h[i]<0)  h[i]=h[i]*-1;
//			printf("p=%d h=%d\n",p[i],h[i]);
		}
		x=p[0]; y=h[0];
		for(i=1;i<n;i++){
			if(y>h[i]){
				x=p[i];  y=h[i];
			}
		}
		printf("%d\n",x);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n, i;
double h, w;

double BMI(double h, double w){
	return w / (h*0.01*h*0.01);
}

int main(){
	while (cin >> n){
		double bmi = INF;
		ll index = INF;
		REP(j, n){
			cin >> i >> h >> w;
			double a = fabs(BMI(h, w) - 22.0) - fabs(bmi - 22.0);
			if (a < -EPS){
				bmi = BMI(h, w);
				index = i;
			}
			if (fabs(a) < EPS){
				index = min(i, index);
			}
		}
		cout << index << endl;
	}
}

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

#define BESTBMI 22
#define MAX 10000

class CDATA {
public:
  int stnum;
  double hei, wei;
  int bmi;
  
  void setBMI() {
    bmi = wei/(hei*hei);
  }
  
  bool operator< (const CDATA &t) const {
    if(abs(22-bmi)==abs(22-t.bmi)) return t.stnum<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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

float getBMI(int h,int w){
	return w/pow(h*0.01,2.0);
}

int main(){
	int n, id, h, w, best_id=0;
	while(cin>>n,n){
		float best=999;
		best_id=999;
		rep(i,n){
			cin>>id>>h>>w;	
			if(abs(getBMI(h,w)-22)<=abs(best-22)){			
				if(abs(getBMI(h,w)-22)==abs(best-22)&&id<best_id){					cout<<"update"<<endl;
					best_id=id;
					best=getBMI(h,w);
				}else if(abs(getBMI(h,w)-22)<abs(best-22)){
					best_id=id;
					best=getBMI(h,w);
				}
			}
		}
		cout<<best_id<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
using namespace std;

int main(){
    int n,i;
    while(cin>>n&&n){
        int ans,p,h,w;
        double min=100,bmi,tmp;
        for(i=0;i<n;i++){
            cin>>p>>h>>w;
            bmi=w/(h*h/10000.0);
            tmp=abs(22.0-bmi);
            if(tmp<min){
                min=tmp;
                ans=p;
            }else if(tmp==min){
                if(p<ans) ans=p;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
    int N;
    while (cin >> N, N) {
        int id = 1000000000;
        double bmi = 22.0;
        for (int i = 0; i < N; i++) {
            int d;
            double h, w;
            cin >> d >> h >> w;
            h /= 100.0;

            if (bmi > abs(22.0 - (w / (h * h)))) {
                id = d;
                bmi = abs(22.0 - (w / (h * h)));
            } else if (bmi == abs(22.0 - (w / (h * h)))) {
                id = min(d, id);
            }
        }

        cout << id << endl;
    }

    return 0;
}