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 <stdio.h>

using namespace std;

int main() {
 double h,w,mb,g;
 int n,mn,i,m;
 while(cin >> m) {
	 if (m==0) break;
     mb=mn=99999999;
	 for (i=0;i<m;i++) {
		 cin >> n >> h >> w;
		 h/=100; g=22-w/(h*h); if (g<0) g=-g;
		 if (mb>=g) { if (mb==g) { if (mn>n) mn=n; } else { mn=n; mb=g;} }
		}
	 cout << mn << endl;
 }
 return 0;
 }

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int n;
  while(cin >> n, n) {
    double mi = INF;
    int res;
    REP(i,n) {
      int a;
      double h, w;
      cin >> a >> h >> w;

      double hoge = abs(22.0-10000.0*w/(h*h));
      if (mi >= hoge) {
        if (mi == hoge) {
          if (a < res)
            res = a;
        } else {
          mi = hoge;
          res = a;
        }
      }
    }
    cout << res << endl;
  }
}

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

using namespace std;


int main() {
	int n, p, minP;
	double h, w, currentDiffBMI, minBMI;

	while (cin >> n, n) {
		minBMI = DBL_MAX;
		for (int i = 0; i < n; i++) {
			cin >> p >> h >> w;
			currentDiffBMI = fabs(w / pow(h, 2) * 10000 - 22);
			//cout << p << ends << currentBMI << endl;
			if (fabs(currentDiffBMI - minBMI) < 0.000001) {
				if (p < minP) {
					minBMI = currentDiffBMI;
					minP = p;
				}		
			}
			else if (currentDiffBMI < minBMI) {
				minBMI = currentDiffBMI;
				minP = p;
			}
			//cout << minBMI << ends << minP << endl;
		}
		cout << minP << endl;
	}

	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int gcd(int a,int b){
  int i;
  if(a<b)
    swap(a,b);
  for(i=1;a%(b/i);)
    for(i++;b%i;i++);  
  return b/i;
}
long long lcm(int a,int b){
  return (long long)a*b/gcd(a,b);
}
int main(){
  int i;
  int n,b,h,w,bb,hh,ww;
  long long l;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    cin>>bb>>hh>>ww;
    for(i=1;i<n;i++){
      cin>>b>>h>>w;
      l=lcm(hh*hh,h*h);
      if(llabs(ww*10000*l/hh/hh-l*22)>llabs(w*10000*l/h/h-l*22)){
	bb=b;
	hh=h;
	ww=w;
      }
    }
    cout<<bb<<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<int, 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(h * h * 22 - w * 10000);
            v.push_back(a);
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
        int i = 1;
        while(v[i+1].first == v[i].first) {
            cout << v[i].second << endl;
            i++;
        }
    }
    return 0;
}

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

constexpr double eps = 1e-12;

int main() {
    int n;
    while(cin >> n, n) {
        double cur = 1e20;
        int id = 1e9;
        for(int i = 0; i < n; ++i) {
            int p; double h, w; cin >> p >> h >> w;
            h /= 100;
            const double bmi = w / h / h;
            if(abs(cur - bmi) < eps) {
                id = min(id, p);
            } else if(abs(22 - cur) > abs(22 - bmi)) {
                cur = bmi;
                id = p;
            }
        }
        cout << id << endl;
    }
}

C++: #include <cmath>
#include <iostream>
using namespace std;
int n, d, h, w, p;
int main() {
	while(scanf("%d", &n), n) {
		double s = 1.0e6;
		for(int i = 0; i < n; i++) {
			scanf("%d%d%d", &d, &h, &w);
			double r = abs(22.0 - 10000.0 * w / h / h);
			if(r < s) s = r, p = d;
		}
		printf("%d\n", p);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int p[1010], h[1010], w[1010];
    for (int i = 0; i < n; i++) {
      cin >> p[i] >> h[i] >> w[i];
    }
    double diff = 1e9;
    for (int i = 0; i < n; i++) {
      double bmi = 1e4 * double(w[i]) / h[i] / h[i];
      if (abs(bmi - 22) < diff) {
        diff = abs(bmi - 22);
      }
    }
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      double bmi = 1e4 * w[i] / h[i] / h[i];
      if (abs(bmi - 22) == diff) {
        ans.emplace_back(p[i]);
      }
    }
    sort(ans.begin(), ans.end());
    for (int i : ans) {
      cout << i << endl;
    }
  }

  return 0;
}