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 <cstdio>

using namespace std;

int main()
{
	char num[25];
	
	while (gets(num) != NULL){
		if (num[0] == '0'){
			break;
		}
		int score = 0;
		int f = 0;
		int i = 0;
		while (num[i + 1] != '\0'){
			if (num[i] == '1' && (num[i + 1] >= '0' && num[i + 1] <= '3')){
				score += 10;
				i += 3;
			}
			else if (num[i] == '1'){
				score++;
				f = 1;
				i += 2;
			}
			else if ('2' <= num[i] && num[i] <= '9'){
				score += (num[i] - '0');
				i += 2;
			}
		}
		if (score > 21){
			score = 0;
		}
		else if (f == 1 && score + 10 <= 21){
			score += 10;
		}
		cout << score << endl;
		score = 0;
		f = 0;
	}
	
	return (0);
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

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

int a[512], p;

int dfs(int n, int c){
  if(n > 21) return 0;
  if(c == p) return n;
  if(a[c] == 1) return max(dfs(n+1, c+1), dfs(n+11, c+1));
  if(a[c] > 10) return dfs(n+10, c+1);
  return dfs(n+a[c], c+1);
}

int main(){
  char str[512];
  while(fgets(str, sizeof(str), stdin) && str[0] != '0'){
    memset(a, 0, sizeof(a));
    char *tp;
    p = 0;
    tp = strtok(str, " ");
    while(tp != NULL){
      a[p++] = atoi(tp);
      tp = strtok(NULL, " ");
    }

    printf("%d\n", dfs(0, 0));
  }
  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 score(int s) {
  if (s>21) return 0;
  else return s;
}

int main() {
  string s;
  while(getline(cin, s)) {
    //cout << s << endl;
    stringstream ss(s);
    int a;
    int sum = 0;
    int num1 = 0;
    while(ss >> a) {
      if (a > 10)
        a = 10;
      sum += a;
      if (a == 1)
        num1++;
    }
    if (a == 0) break;
    int ans = 0;
    REP(i,num1+1) {
      ans = max(ans, score(sum + i*10));
    }
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

vector<int> split(string s){
    if(s.size()==1) return vector<int>(1,stoi(s));
    vector<int> ret;
    int x = -1;
    REP(i,s.size()){
	if(s[i] == ' '){
	    ret.PB(stoi(s.substr(x+1,i-x-1)));
	    x = i;
	}
    }
    ret.PB(stoi(s.substr(x+1,s.size()-x)));
    return ret;
}

int main(){
    while(true){
	string s;
	getline(cin,s);
	if(s == "0") break;
	vector<int> c = split(s);
	int ans = 0;
	bool flg = false;
	REP(i,c.size()){
	    if(c[i] >= 10) ans += 10;
	    else ans += c[i];
	    if(c[i]==1) flg = true;
	}
	if(ans <= 11 && flg) ans += 10;
	if(ans > 21) ans = 0;
	cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() {
	string a;
	while (getline(cin, a)) {
		if (a == "0")break;
		vector<int>s;
		string c="";
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == ' ') { s.push_back(Parse(c)); c = ""; }
			else c += a[b];
		}
		s.push_back(Parse(c));
		int m = 0;
		int n = 0;
		for (int d = 0; d < s.size(); d++) {
			if (s[d] > 9)m += 10;
			else if (s[d] > 1)m += s[d];
			else n++;
		}
		int f = ((21 - m) - n) / 10;
		if (f > n)f = n;
		m += f * 11 + (n - f);
		if (m > 21)m = 0;
		cout << m << endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int solve(vector<int> &v, int i, int sum){

  if(sum > 21) return 0;

  if(i == v.size()){
    if(sum > 21) sum = 0;
    return sum;
  }
  int res = 0;

  if(v[i] == 1){
    res = max(solve(v, i+1, sum+1), solve(v, i+1, sum+11));
  }else if(v[i] >= 2 && v[i] <= 9){
    res = solve(v, i+1, sum+v[i]);
  }else{
    res = solve(v, i+1, sum+10);
  }
  return res;
}

int main(){

  string s;
  while(true){
    getline(cin, s);
    if(s == "0") break;

    vector<int> v;
    int len = s.length();
    int idx = 0;
    REP(i,len){
      if(s[i] == ' '){
        //cout << s.substr(idx, i-idx) << endl;
        v.pb(stoi(s.substr(idx, i-idx)));
        idx = i + 1;
      }
    }
    v.pb(stoi(s.substr(idx, len-idx)));
    cout << solve(v, 0, 0) << endl;
  }

  return 0;
}

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

int main(){
    string s;
    while(getline(cin,s)){
        if(s == "0")    break;

        int sum = 0;
        int one = 0;

        stringstream ss(s);
        int c;
        while(ss >> c){
            if(c == 1)  one++;
            if(c > 10)  c = 10;
            sum += c;
        }

        if(sum > 21){
            sum = 0;
        }else if(one > 0){
            while(one > 0 && sum+10 <= 21){
                sum += 10;
                one--;
            }
        }

        cout << sum << endl;
    }
    return 0;
}