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 <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
  while( 1 ) {
    string line;
    getline( cin, line );
    vector<int> cards;
    istringstream iss(line);
    string item;
    while( iss >> item ) {
      cards.push_back( atoi( item.c_str() ) );
    }
    if( !cards[ 0 ] ) { return EXIT_SUCCESS; }
    sort( cards.begin(), cards.end() );
    int one_num = 0;
    for( ; cards[ one_num ] == 1; one_num++ ); // counts '1' cards
      
    int len = cards.size();
    int sum = 0;
    for( int i = 0; i < len; i++ ) {
      sum += min( cards[ i ], 10 );
    }
    sum = ( sum > 21 ? 0 : sum ); 
    while( one_num > 0 ) {
      if( sum + 10 > 21 ) break;
      sum += 10;
      one_num--;
    }
    cout << sum << endl;
  }
}

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

int main() {
  int n, p, q, s, t;
  int a[60];
  char buf[200];
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d", &t);
    if (!t) break;
    p = n = 0;
    while (sscanf(buf+p, "%d%n", &a[n], &q) == 1) {
      ++n;
      p += q;
    }
    s = t = 0;
    for (int i=0; i<n; i++) {
      if (a[i] < 10) {
        s += a[i];
        if (a[i] == 1) {
          ++t;
        }
      } else {
        s += 10;
      }
    }
    if (s > 21) {
      s = 0;
    } else {
      s += 10 * min(t, (21-s)/10);
    }
    printf("%d\n", s);
  }
  return 0;
}

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

using namespace std;

int main()
{
  string cards;
  while(getline(cin, cards), cards != "0"){
    stringstream ss(cards);
    int ans = 0, x;
    bool one = false;
    while(ss >> x){
      ans += min(x, 10);
      if(x == 1) one = true;
    }
    if(ans > 21) cout << 0 << endl;
    else cout << (one ? ((ans + 10 <= 21) ? ans + 10 : ans) : ans) << endl;
  }
  return 0;
}

C++: // 2011/02/26 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	while(true){
		string str;
		getline(cin, str);
		istringstream ist(str);

		int crd;
		int sum = 0;
		int flg = false;
		while(ist >> crd){
			if(crd==0){
				return 0;
			}
			else if(crd==1){
				sum += 1;
				flg = true;
			}
			else if(crd>=2&&crd<=9){
				sum += crd;
			}
			else if(crd>=10&&crd<=13){
				sum += 10;
			}

			if(sum>21)
				break;
		}

		if(sum<=11&&flg)
			sum += 10;

		if(sum>21)
			sum = 0;

		cout << sum << endl;
	}
}

C++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

vector<int> split(string delim,string str){
	vector<int> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				int num = atoi(str.substr(i,j-1).c_str());
				if(str.substr(i,j-1).size() >0 ) res.push_back(num);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

int main(){
	string str;
	while(getline(cin,str)){
		vector<int> data = split(" ",str);
		if(data.size()==1 && data[0]==0) break;
		set<int>* dp = new set<int>[data.size()+1]; 

		dp[0].insert(0);
		for(int i=0;i<data.size();i++){
			if(data[i] == 1){
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+1);
					dp[i+1].insert(*it+11);
				}
			}
			else if(2 <= data[i] && data[i] <= 9){
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+data[i]);
				}
			}
			else{
				for(set<int>::iterator it = dp[i].begin(); it != dp[i].end(); it++){
					dp[i+1].insert(*it+10);
				}
			}
		}

		int res=MAX_N;
		for(set<int>::iterator it = dp[data.size()].begin(); it != dp[data.size()].end(); it++){
			if(*it <= 21 && abs(*it-21) < abs(res-21)){
				res = * it;
			}
		}

		printf("%d\n",res == MAX_N ? 0 : res);
	}
}

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++;
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
vector<string> split(const string &str, char delim) {
	vector<string> res;
	size_t current = 0, found;
	while ((found = str.find_first_of(delim, current)) != string::npos) {
		res.push_back(string(str, current, found - current));
		current = found + 1;
	}
	res.push_back(string(str, current, str.size() - current));
	return res;
}

int main() {
	string st; 
	while (getline(cin,st)) {
		if (st == "0")break;
		vector<string>sts(split(st,' '));
		vector<int>nums(sts.size());
		for (int i = 0; i < sts.size(); ++i) {
			nums[i] = stoi(sts[i]);
		}
		bool ace = false;
		for (int i = 0; i < sts.size(); ++i) {
			if (nums[i] >= 10)nums[i] = 10;
		}
		int sum = 0;
		for (int i = 0; i < sts.size(); ++i) {
			if (nums[i] == 1) {
				ace = true;
			}

			sum += nums[i];
		}
		if (sum <= 11 && ace)sum += 10;
		if (sum >= 22)sum = 0;
		cout << sum << endl;
	}
	return 0;
}

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 pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	string str;
	while(true){
		getline(cin,str);
		if(str.size() == 1 && str[0] == '0')break;
		vi num;
		stringstream ss(str);
		int tmp;
		while(ss >> tmp){
			num.PB(tmp);
		}
		sort(num.begin(),num.end());
		int one = 0;
		int ans = 0;
		rep(i,num.size()){
			if(num[i]==1)one++;
			if(num[i] > 1){
				if(num[i] > 9){
					ans+=10;
				}
				else{
					ans+=num[i];
				}
			}
		}
		if(one == 1){
			ans += 11;
		}
		else{
			ans += one;
		}
		if(ans >= 22)ans = 0;
		printf("%d\n",ans);
    }
    return 0;
}