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 <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 + 1; 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 <sstream>
#include <bitset>

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        ss << s;
        vector<int> c;
        int temp;
        while(ss >> temp) c.push_back(temp);
        bitset<22> bits;
        bits.set(0);
        for(int i=0;i<c.size();i++){
            bitset<22> newbits;
            int x = c[i];
            for(int j=0;j<22;j++){
                if(!bits[j]) continue;
                if(x>=10) x = 10;
                if(x != 1 && j+x <= 21) newbits.set(j+x);
                if(x == 1){
                    if(j+11 <= 21) newbits.set(j+11);
                    if(j+1 <= 21) newbits.set(j+1);
                }
            }
            cout << newbits <<endl;
            bits = newbits;
        }
        int mm=0;
        for(int i=0;i<22;i++){
            if(bits[i]) mm = i;
        }
        cout << mm << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s!="0"){
    stringstream ss(s);
    int x=0,i,ans;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    while(ss>>x){
      si=v.size();
      for(i=0;i<si;i++){
	if(x==1){
	  v.push_back(v[i]+11);
	  v[i]++;
	}else if(x>10) v[i]+=10;
	else v[i]+=x;
      }
    }
    sort(v.begin(),v.end());
    ans=0;
    for(i=0;i<v.size();i++){
      if(v[i]<=21) ans=v[i];
    }
    cout << ans << endl;
    s="";
  }  
  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 (1) {
		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++;
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	}
}

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

int main()
{
  cin >> noskipws;
  while(true)
  {
    int cards[21];
    int card_num;
    int ace_num = 0;   //  エースがあるかどうか
    for (card_num = 0; card_num<21; card_num++)
    {
      cin >> cards[card_num];
      if ( cards[card_num] == 0 ) return 0;
      if ( cards[card_num] == 1 ) ace_num++;
      char ws;
      cin >> ws;
      if ( ws != ' ' )
      {
        card_num++;
        break;
      }
    }

    int point = 0;
    for (int i=0; i<card_num; i++)
    {
      if ( cards[i] < 10 )
      {
        point += cards[i];
      }
      else
      {
        point += 10;
      }
    }
    if ( point > 21 )
    {
      point = 0;
    }

    while ( ace_num > 0 && point <= 11 )
    {
      point += 10;
      ace_num--;
    }

    cout << point << endl;

  }
}

C++: #include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int main(){
	string s;
	int sum,ans,now,cou,pre;
	priority_queue<int> que;
	while(getline(cin,s),s[0]!='0'){
		sum=0;
		for(int i=0;i<s.size();i++){
			if(isdigit(s[i])){
					sum=sum*10+(s[i]-'0');
			}
			else{
				que.push(sum);
				sum=0;
			}
		}
		cou=0;
		que.push(sum);
		ans=0;
		while(!que.empty()){
			now=que.top();
			que.pop();
			if(now>=2&&now<=9)
				ans+=now;
			else if(now>9)
				ans+=10;
			else if(now==1)
				cou++;
		}
		int m=ans;
		if(cou+ans>21)
			cout<<'0'<<endl;
		else{
		for(int i=0;i<=cou;i++){
			pre=m+cou-i+i*11;
			if(pre<=21){
				ans=max(pre,ans);
			}
		}
		if(ans>21)
		cout<<'0'<<endl;
		else cout<<ans<<endl;
		}
	}
	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[100], p;

int dfs(int i, int n){
  if(i == p){
    if(n > 21) return 0;
    return n;
  }

  if(a[i] == 1) return max(dfs(i+1, n+1), dfs(i+1, n+11));
  if(a[i] > 10) return dfs(i+1, n+10);
  return dfs(i+1, n+a[i]);
}

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

    //    rep(i, p) printf("%d ", a[i]); puts("");

    printf("%d\n", dfs(0, 0));
  }
  return 0;
}

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

int main()
{
  cin >> noskipws;
  while(true)
  {
    int cards[21];
    int card_num;
    int ace_num = 0;   //  エースがあるかどうか
    for (card_num = 0; ; card_num++)
    {
      if ( card_num == 21 )
      {
        int dummy;
        char ws;
        bool b = true;
        while (b)
        {
          cin >> dummy >> ws;
          if ( ws != ' ' )
          {
            b = false;
          }
        }
        break;
      }
      cin >> cards[card_num];
      if ( cards[card_num] == 0 ) return 0;
      if ( cards[card_num] == 1 ) ace_num++;
      char ws;
      cin >> ws;
      if ( ws != ' ' )
      {
        card_num++;
        break;
      }
    }

    int point = 0;
    for (int i=0; i<card_num; i++)
    {
      if ( cards[i] < 10 )
      {
        point += cards[i];
      }
      else
      {
        point += 10;
      }
    }

    while ( ace_num > 0 && point <= 11 )
    {
      point += 10;
      ace_num--;
    }
    if ( point > 21 )
    {
      point = 0;
    }

    cout << point << endl;

  }
}