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

int main() {
  string s;
  while(getline(cin, s)) {
    if(s[0] == '0') break;
    vector<int> card;
    int one = 0;
    for(int i = 0; i < s.size(); i++) {
      if('0' <= s[i] && s[i] <= '9') {
        if(i+1 != s.size() && '0' <= s[i+1] && s[i+1] <= '2') {
          card.push_back((s[i]-'0')*10 + (s[i+1]-'0'));
          i++;
        } else {
          card.push_back(s[i]-'0');
        }
        if(i > 0 && s[i-1] == ' ' && s[i] == '1') one++;
      }
    }
    sort(card.begin(), card.end(), greater<int>());

    int ans = 0;
    for(int i = 0; i < card.size(); i++) {
      if(card[i] != 1) {
        if(card[i] > 10) ans += 10;
        else ans += card[i];
      } else {
        if(ans+10+one <= 21) ans += 11;
        else ans += 1;
        one--;
      }
    }
    if(ans > 21) ans = 0;
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <sstream>
using namespace std;
main()
{
    string s;
    while( getline( cin, s ), s != "0" )
    {
        stringstream ss(s);
        ss << s;
        int sum = 0, one = 0, a;
        while( ss >> a )
        {
            if( a == 1 ) one++;
            else sum += min( 10, a );
        }
        if( one > 21 || sum > 21 || one + sum > 21 )
        {
            cout << 0 << endl;
        }
        else
        {
            int p = ( 11 * one + sum - 21 + 10 - 1) / 10;
            cout << p + ( one - p ) * 11 + sum << endl;
        }
        
    }
    return 0;
}

C++: #include<stdio.h>

int main(void){
	int sum=0,card,one=0,i;
	char code;

	while(0==0){
		scanf("%d%c",&card,&code);
		if(card>10) card=10;
		else if(card==1) one++;

		sum+=card;

		if(code=='\n'){
			if(sum==0) break;
			else if(sum>21) sum=0;

			else if(one>0){
				for(i=0;i<one;i++)
					if(sum<=11) sum+=10;
			}
			printf("%d\n",sum);
			sum=0; one=0;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S; int p[11];
char V[11] = "0123456789";
int main() {
	while (true) {
		cin >> S; if (S == "0") { break; }
		S += ' '; string T = "";
		for (int i = 0; i < 11; i++) { p[i] = 0; }
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == ' ') {
				if (T.size() >= 2) { p[10]++; }
				else {
					for (int j = 1; j < 10; j++) {
						if (V[j] == T[0]) { p[j]++; }
					}
				}
				T = "";
			}
			else {
				T += S[i];
			}
		}
		int sum = 0;
		for (int i = 0; i < 11; i++) { sum += p[i] * i; }
		if (sum <= 11 && p[1] >= 1) { sum += 10; }
		if (sum >= 22) { sum = 0; }
		cout << sum << endl;
	}
	return 0;
}

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

int main() {
	while(1) {
		char input[1024];
		cin.getline(input, sizeof input);
		if(strcmp(input, "0") == 0) {
			break;
		}
		stringstream ss(input);
		vector<int> v;
		int num;
		while(ss >> num) {
			v.push_back(num);
		}
		sort(v.begin(), v.end(), greater<int>());
		int n = v.size();
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if(v[i] == 1) {
				if(sum + 10 > 21 - (n - i + 1)) {
					sum++;
				} else {
					sum += 10;
				}
				continue;
			}
			else if(v[i] >= 10) {
				sum += 10; continue;
			} else {
				sum += v[i];
			}
		}
		if(sum > 21) cout << 0 << endl;
		else cout << sum << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; ++i )
vector<int>card;
int ans;
void bfs(int now,int sum){
  if(sum > 21) return;
  if(now == card.size()){
    ans = max(ans,sum);
    return;
  }
  bfs(now+1,sum+min(card[now],10));
  if(card[now] == 1) bfs(now+1,sum+11);
}
int main(){
  string s;
  while(getline(cin,s) , s != "0"){
    card.clear();
    ans = 0;
    int a = 0;
    rep(i,s.size()){
      if(isdigit(s[i])) a = a * 10 + s[i] - '0';
      else if(s[i] == ' '){
        card.push_back(a);
        a = 0;
      }
    }
    card.push_back(a);

    bfs(0,0);
    cout << ans << endl;
  }
}

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

int main()
{
  string s;
  while (getline(cin, s)) {
    if (s.find_first_of("\n") != string::npos)
      s.erase(s.end()-1);
    if (s.find_first_of("\r") != string::npos)
      s.erase(s.end()-1);

    if (s == "0")
      break;

    istringstream iss(s);
    int one = 0, sum = 0;
    while (!iss.eof()) {
      int num;
      iss >> num;

      if (num == 1)
	++one;
      else if (num >= 10)
	sum += 10;
      else
	sum += num;
    }

    int ans = 0;
    for (int i = 0; i <= one; ++i) {
      int p = i + (one-i)*11 + sum;
      if (p > 21)
	p = 0;
      ans = max(ans, p);
    }

    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//split delimiter??§?????????
vector<string> split(const string& input, char delimiter) {
	vector<string> ret;
	istringstream stream(input);
	string s;
	while (getline(stream, s, delimiter)) ret.push_back(s);
	return ret;
}
#define MAX 50
signed main() {
	bool a[2][1000] = {};
	for (string s; getline(cin, s) && s != "0";) {
		fill(a[0], a[2], false);
		a[0][0] = true;
		vector<string> t = split(s, ' ');
		rep(i, 0, t.size()) {
			rep(j, 0, MAX)a[(i + 1) % 2][j] = false;
			rep(j, 0, MAX - 20) {
				if (stoi(t[i]) <= 10)
					if (a[i % 2][j])a[(i + 1) % 2][stoi(t[i]) + j] = true;
				if (stoi(t[i]) >= 11)
					if (a[i % 2][j])a[(i + 1) % 2][10 + j] = true;
				if (stoi(t[i]) == 1)
					if (a[i % 2][j])a[(i + 1) % 2][11 + j] = true;
			}
		}
		a[t.size() % 2][0] = true;
		rrep(i, 0, 22) {
			if (a[t.size() % 2][i]) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main()
{
  string s;
  char *c;
  int i, score, ace;
  while (getline(cin,s)) {
    if (s[0]=='0') break;
    score = 0;
    ace = 0;
    c = strtok((char*)s.c_str(), " ");
    while (c != NULL) {
      if (atoi(c) > 9) score += 10;
      else score += atoi(c);
      if (atoi(c) == 1) ace++;
      c = strtok(NULL, " ");
    }
    while (ace--) {
      if (score + 10 > 21) break;
      score += 10;
    }
    if (score > 21) score = 0;
    cout<<score<<endl;
  }
}