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>

using namespace std;

int main(int argc, char **argv)
{
	int n, id, s;
	double h, w, t, tmp;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		
		cin >> s >> h >> w;
		t = (w / (h*h))* 10000 - 22.0;
		
		if(t < 0){
			t = -t;
		}

		for(int i = 1; i < n; i++){
			cin >> id >> h >> w;
			
			tmp = (w / (h*h))*10000 - 22.0;
			if(tmp < 0){
				tmp = -tmp;
			}
			
			if(t > tmp){
				t = tmp;
				s = id;
			}
		}
		
		cout << s << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,h,w;
	int j;
	double best;
	double bmi;
	int a,sa;
	
	scanf("%d",&n);
	best=22.0;
	while(n!=0){
		sa=99999;
		for(j=0;j<n;j++){
			scanf("%d %d %d",&i,&h,&w);
			bmi=(double)w/(h*h)*10000;
			if(best<bmi){
				bmi=bmi-best;
			}
			else {
				bmi=best-bmi;
			}
			if(sa>bmi){
				a=i;
				sa=bmi;
			}
			else if(sa==bmi && a>i){
				a=i;
			}	
		}
		printf("%d\n",a);
		scanf("%d",&n);

	}
	return 0;
}

C++: #include <iostream>
#include <cmath>

using namespace std;

struct Human {
    int id, w;
    double h, bmi;
    void setter(int _id, int _w, double _h) {
        id = _id;
        w = _w;
        h = _h / 100.0;
        bmi = w / h / h;        
    }
};
bool operator <(const Human &a, const Human &b)
{
    return abs(22 - a.bmi) != abs(22 - b.bmi) ? abs(22 - a.bmi) < abs(22 - b.bmi) : a.id < b.id;
}

int main()
{
    int n;
    int id, h, w;

    while (cin >> n, n) {
        Human ans, tmp;

        cin >> id >> h >> w;
        ans.setter(id, w, h);

        for (int i = 0; i < n - 1; i++) {
            cin >> id >> h >> w;
            tmp.setter(id, w, h);

            if (tmp < ans)
                ans = tmp;
        }
        cout << ans.id << endl;
    }

    return 0;
}

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

int main(void){
  int n ;
  while(cin>>n,n){
    double min_num,min_bmi;
    double h,w;
    int num;
    cin>>min_num>>h>>w;
    h/=100;
    min_bmi = fabs(w / (h * h) - 22);
    for(int i = 0 ; i < n - 1 ; i ++){
      cin>>num>>h>>w;
      h/=100;
    double bmi = fabs(w / (h*h) - 22);
      //cout<<num<<" "<<h<<" "<<w<<" "<<bmi<<endl;
      if(min_bmi > bmi){
        min_num = num;
        min_bmi = bmi;
      }
      //cout<<min_num<<" "<<min_bmi<<":"<<num<<" "<<bmi<<endl;
    }
    cout<<min_num<<endl;
  }
  
}

C++: // AOJ 0159
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		vector < pair <int, int> > d;
		double id, h, w;
		for (int i = 0; i < n; i++){
			cin >> id >> h >> w;
			h /= 100.0;
			d.push_back(make_pair(abs((w / (h * h)) - 22.0), id));
		}
		sort(d.begin(), d.end());
		// for (int i = 0; i < n; i++){
		// 	cout << d[i].first << " " << d[i].second << endl;
		// }
		cout << d[0].second << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		int answer = -1;
		double good = 0.0;

		for ( int i = 0; i < n; i++ )
		{
			int no, h, w;
			cin >> no >> h >> w;
			double bmi = (double)w / ( h * h / 10000.0 );
			double score = fabs( 22.0 - bmi );
			if ( answer == -1 || score < good )
			{
				answer = no;
				good = score;
			}
		}

		cout << answer << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.bestbody", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if
		multimap <double, int> rank;
		int j;

		for (j = 0; j < n; ++j){
			int i, h, w; // index, h[cm], w[kg];  
			getline (cin, str );
			stringstream ss(str);
			ss >> i >> h >> w;
			double bmi = (double)w / ( (h/100.)*(h/100.) );
			double diff = fabs (bmi - 22.0);
			rank.insert (make_pair (diff, i ) );
		} // end for
		multimap <double, int>::iterator it = rank.begin();
		cout << (*it).second << endl;
	} // end loop
		
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		vector<int> cand;
		double mindiff = 1e+10;
		double bmi;
		int i,h,w;
		for(int j=0;j<n;j++){
			cin >> i >> h >> w;
			bmi = (double)w / (((double)h/100)*((double)h/100));
			//cout << i << " " << h  << " " << w << endl;
			//cout << bmi << endl;
			if(fabs(22-bmi) < mindiff){
				cand.clear();
				mindiff = fabs(22-bmi);
				cand.push_back(i);
			}else if(fabs(mindiff - fabs(22-bmi)) < 1e-4 ){
				cand.push_back(i);
			}
		}
		sort(cand.begin(),cand.end());
		cout << cand[0] << endl;
	}
}

C++: #include<cmath>
using namespace std;
int main(){
	int n,mi,id;
	while(cin>>n,n){
		double mx=0,h,w;
		for(int i=0;i<n;i++){
			cin>>id>>h>>w; h/=100;
			if(abs(mx-22)>abs(1.*w/h/h-22))mx=1.*w/h/h,mi=id;
		}
		cout<<mi<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)return 0;
		int maxnum;
		double maxbmi;
		int num;
		double x, y;
		cin >> num >> x >> y;
		x /= 100;
		x *= x;
		y /= x;
		maxnum = num;
		maxbmi = y;
		for (int i = 1; i < n; i++){
			cin >> num >> x >> y;
			x /= 100;
			x *= x;
			y /= x;
			if (abs(22 - maxbmi) > abs(22 - y)){
				maxnum = num;
				maxbmi = y;
			}
			else if (abs(22 - maxbmi) == abs(22 - y)){
				maxnum = min(maxnum, num);
			}
		}
		cout << maxnum << endl;
	}
}