Go: package main

import (
	"bufio"
		"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		cards := make([]int, len(buf))
		for i := range buf {
			cards[i], _ = strconv.Atoi(buf[i])
		}
		if cards[0] == 0 {
			break
		}
		sum, ace := 0, 0
		for _, v := range cards {
			if v == 1 {
				v = 0
				ace++
			} else if v >= 10 {
				v = 10
			}
			sum += v
			if sum+ace > 21 {
				break
			}
		}
		if sum+ace > 21 {
			fmt.Println(0)
		} else if ace > 0 && sum+ace<= 11 {
			fmt.Println(sum+ace+10) // 1->11なるAceは高々1枚
		} else {
			fmt.Println(sum+ace)
		}
	}
}

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

int main() {
  int n, p, q, s, t;
  vector<int> v;
  string buf;
  while (1) {
    getline(cin, buf);
    istringstream iss(buf);
    iss >> p;
    if (!p) break;
    v.clear();
    v.push_back(p);
    while (iss >> p) {
      v.push_back(p);
    }
    s = t = 0;
    for (int i=0; i<(int)v.size(); i++) {
      if (v[i] < 10) {
        s += v[i];
        if (v[i] == 1) {
          ++t;
        }
      } else {
        s += 10;
      }
    }
    if (s > 21) {
      s = 0;
    } else {
      s += 10 * min(t, (21-s)/10);
    }
    cout << s << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int one = 0;
vector<int> split(const string &str, char delim){
    istringstream iss(str); string tmp; vector<int> res;
    while(getline(iss, tmp, delim)){
        int n = atoi(tmp.c_str());
        if(n == 1) one++;
        else{
            if(n >= 10) n = 10;
            res.push_back(n);
        }
    }
    return res;
}

int main(){
    string str;
    while(getline(cin, str)){
        one = 0;
        int ans = 0;
        if(str == "0") break;
        vector<int> num = split(str, ' ');
        REP(i, num.size()) ans += num[i];


        int onenum = one * 11;
        REP(i, one){
            if(onenum + ans >= 22) onenum -= 10;
        }

        ans += onenum;
        ans = (ans < 22)? ans : 0;
        cout <<ans <<endl;
    }
    return 0;
}

C++: #include <iostream>

int getScore(int h[], int n)
{
	int res = 0;
	int one_count = 0;
	for (int i=0; i<n; i++) {
		if (2 <= h[i] && h[i] <= 9) res += h[i];
		else if (h[i] >= 10) res += 10;
		else { res++; one_count++; }
	}
	if (res >= 22) return 0;
	else {
		while (res<=11 && one_count>0) { res += 10; one_count--; }
		return res;
	}
}

int main()
{
	int hand[100];
	std::string input;
	while (true) {
		getline(std::cin, input);
		int offset = 0;
		int pos;
		int index = 0;
		int h;
		while ( (pos = input.find(' ', offset)) != std::string::npos ) {
			h = std::stoi(input.substr(offset, pos-offset));
			hand[index] = h; index++;
			offset = pos + 1;
		}
		h = std::stoi(input.substr(offset));
		if (h==0) break;
		hand[index] = h;
		std::cout << getScore(hand, index+1) << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	char str[30];

	while( cin.getline( str, 30 ) && str[0] != '0' ){
		char *t;
		data.clear();
		t = strtok( str, " " );
		data.push_back( atoi( t ) );
		while( ( ( t = strtok( NULL, " " ) ) != NULL ) ){
			data.push_back( atoi( t ) );
		}

		int answer;
		int count;

		answer = 0;
		count = 0;

		for( int i = 0;i < data.size();i++ ){
			if( data[i] >= 10 ) answer += 10;
			else answer += data[i];
			if( data[i] == 1 ) count++;
		}
		if( answer > 21 ) answer = 0;
		if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 > 21 ) break;
				answer += 10;
			}
		}
		cout << answer << endl;
	}
	return 0;
}

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

main(){
    string line;
    while(1){
	getline(cin, line);
	if ( line == "0" ) break;
	stringstream sin(line);
	int x, one = 0, sum = 0;
	while( sin >> x ){
	    if ( 10 <= x ) x = 10;
	    if ( x == 1 ) one++;
	    sum += x;
	}

	for ( int i = 0; i < one; i++ ){
	    if ( sum + 10 <= 21 ) sum += 10;
	}
	if ( sum > 21 ) sum = 0;
	cout << sum << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi cards;
int ans;
void solve(int dep,int sum){
    if(dep == cards.size()){
        ans = max(ans,sum);
        return ;
    }
    if(cards[dep] == 1){
        if(sum+1 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+1);
        }

        if(sum+11 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+11);
        }
    }
    else if(cards[dep] > 9){
        if(sum+10 > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+10);
        }
    }
    else{
        if(sum+cards[dep] > 21){
            solve(dep+1,0);
        }
        else{
            solve(dep+1,sum+cards[dep]);
        }
    }
    return ; 
}
int main(){
    string str;
    while(getline(cin,str)){
        stringstream ss(str);
        int tmp;
        cards.clear();
        while(ss >> tmp){
            cards.PB(tmp);
        }
        if(cards[0] == 0)break;
        ans = -INF;
        solve(0,0);
        printf("%d\n",ans);
    }
    return 0;
}

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

int main()
{
  int n;
  char c;

  while (1){
    int sum = 0, ace = 0;
    bool fin = false;
    do {
      scanf("%d", &n);
      if (n == 0){
        fin = true;
        break;
      }
      if (n == 1){
        ace++;
      }
      else {
        sum += min(n, 10);
      }
    } while (scanf("%c", &c), c != '\n');

    if (fin){
      break;
    }
    int rs = 0;
    for (int i = 0; i <= ace; i++){
      int tmp = sum + i + (ace - i) * 11;
      if (tmp > 21){
        tmp = 0;
      }
      rs = max(tmp, rs);
    }
    printf("%d\n", rs);
  }

  return (0);
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	char str[30];

	while( cin.getline( str, 30 ) && str[0] != '0' ){
		char *t;
		data.clear();
		t = strtok( str, " " );
		data.push_back( atoi( t ) );
		while( ( ( t = strtok( NULL, " " ) ) != NULL ) ){
			data.push_back( atoi( t ) );
		}

		int answer;
		int count;

		answer = 0;
		count = 0;

		for( int i = 0;i < data.size();i++ ){
			if( data[i] >= 10 ) answer += 10;
			else answer += data[i];
			if( data[i] == 1 ) count++;
		}
		if( answer > 21 ) answer = 0;
		else if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 > 21 ) break;
				answer += 10;
			}
		}
		cout << answer << endl;
	}
	return 0;
}