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<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&&s[d]<14)m += 10;
			else if (s[d] > 1&&s[d]<10)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}

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[14], p;

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

    //    rep(i, p) printf("%d ", a[i]); puts("");
    int res = 0;
    a[10] += a[11]; a[10] += a[12]; a[10] += a[13];
    REP(i, 2, 11) res += a[i]*i;
    //    printf("%d\n", res);
    //    printf("%d\n", a[1]);
    if(a[1]) res += (res+11+a[1]-1>21)?(a[1]):(11+a[1]-1);
    if(res > 21) res = 0;

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

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
 char c[256]; 
 int d[100],i,s,p,f;
 while(true) {
 for (i=0;i<255;i++) c[i]=1;
 i=p=0;
 gets(c);
 if (c[0]=='0') break;
 while(true) {
	 if (c[p+2]==' ' || c[p+2]=='\0') { d[i]=(c[p]-'0')*10+(c[p+1]-'0'); p+=3;}
	 else if (c[p+1]==' ' || c[p+1]=='\0') { d[i]=(c[p]-'0'); p+=2;}
	 if (c[p-1]=='\0') break;
	 i++;
 }
 for (s=0,f=0;i>=0;i--) if (d[i]>0 && d[i]<10) { s+=d[i]; if (d[i]==1) f=1;} else s+=10;
 if (f==1 && s+10<22) s+=10;
 if (s>21) s=0;
 cout << s << endl;
 }
 return 0;

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){

  int n;
  char c;
  int sum = 0;
  vector<int> V;

  while(1){
    scanf("%d%c",&n,&c);
    if(n == 0) break;
    
    V.push_back(n);
    if(c == '\n'){
      int first = 0;
      for(int i = 0; i < V.size(); i++){
	if(V[i] > 10 && V[i] <= 13 ) V[i] = 10;

	if(V[i] != 1) sum += V[i];
	else first++;
      }

      if(first > 0){
	int leaves = 21;
	leaves -= sum;
	leaves -= first;
	
	for(int i = 0; i < first;i++){
	  if(leaves >= 10) leaves -= 10;
	}
	sum = 21-leaves;

      } 
      if(sum > 21) sum = 0;
    }else{
      continue;
    }
    cout << sum << endl;
    sum = 0;
    V.clear();
  }

  return 0;
}

C++: #include<cstdio>
#include<sstream>
#define MAX(x,y) ((x>y)?x:y)
using namespace std;

int main(){
	int i,j,x,sum,f,ans;
	char s[512];
	
	while(fgets(s,512,stdin)!=NULL){
		istringstream ss(s);
		f=sum=0;
		while(ss>>x){
			if(x==0)goto fin;
			if(x==1)f++;
			else if(x>9)sum+=10;
			else sum+=x;
		}
		ans=0;
		for(i=0;i<=f;i++){
			x=sum+i+11*(f-i);
			if(x>21)x=0;
			ans=MAX(ans,x);
		}
		printf("%d\n",ans);
	}
	fin:
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>

std::vector<int> split(std::string s, char delim){
  if(s.length() == 0)return std::vector<int>{};
  int prev = 0;
  std::string t;
  std::vector<int> res;
  // std::cout << "len:" << s.length() << std::endl;
  for (int i = 1; i < s.length(); i++) {
    if(s[i] == delim) {
      t = s.substr(prev, i - prev);
      res.push_back(std::stoi(t));
      prev = i;
    }
  }
  if(prev != s.length() - 1){
    t = s.substr(prev, s.length() - prev);
    res.push_back(std::stoi(t));
  }
  return res;
}


int main(){
  int n;
  while(std::cin >> n, n){
    if(n == 0)break;
    std::string s;
    std::getline(std::cin, s);
    std::vector<int> cards = split(s, ' ');
    cards.push_back(n);
    int val = 0, num1 = 0;
    // std::cout << "cards:" << std::endl;
    // for (int i = 0; i < cards.size(); i++) {
    //   std::cout << cards[i] << std::endl;
    // }
    for (int i = 0; i < cards.size(); i++) {
      val += std::min(cards[i], 10);
      if(cards[i] == 1)num1++;
    }
    for (int i = 0; i < num1 and val <= 11; i++) val += 10;
    if(val > 21)val = 0;
    // std::cout << "val:" << val << std::endl;
    std::cout << val << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s=="0") break;
		stringstream ss;
		vector<int> a;
		int n,f=0,sum=0;
		ss<<s;
		while(ss>>n){
			if(n==1)f=1;
			a.push_back((n>=10)?10:n);
			if(ss.eof()) break;
		}
		for(int i=0;i<a.size();++i) sum+=a[i];
		if(f&&sum<=11) sum+=10;
		if(sum>21)cout<<0<<endl;
		else cout<<sum<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

void Atoi(vector<int>&, string);
int Blackjack(vector<int>);
bool Searhone(int);

int main(){
  int i, n, result;
  string line;
  vector<int> Number; 

  while(1){
    getline(cin, line);
    if(line == "0") break;

    Atoi(Number, line);
    result = Blackjack(Number);
    cout << result << endl;
    Number.clear();
  }
  return 0;
}

void Atoi(vector<int>& n, string s){
  int i=0, x;

  while(i < s.size()){
    if(s[i+1] == ' ' || i == s.size()-1){
      x = s[i] - 48;
      i += 2;
    }else{
      x = 10 * (s[i] - 48) + (s[i+1] - 48);
      i += 3;
    }
    n.push_back(x);
  }
}

int Blackjack(vector<int> n){
  int k, sum=0, onecount=0;
  vector<int>::iterator i, j;

  for(k=0; k<n.size(); ++k){
    if(n[k] > 10) n[k] = 10;
  }

  i = partition(n.begin(), n.end(), Searhone);
  j = n.begin();
  while(j != i){
    if(sum <= 21 - *j)
      sum += *j;
    else
      return 0;
    ++j;
  }

  if(i != n.end()){
    while(i != n.end()){
      ++onecount;
      ++i;
    }

    if(onecount == 1){
      if(sum <= 10)
	sum += 11;
      else if(sum <= 20)
	sum++;
      else
	sum = 0;
    }else{
      if(sum <= 10 - (onecount-1))
	sum = sum + 11 + (onecount-1);
      else if(sum <= 20 - onecount)
	sum += onecount;
      else
	sum = 0;
    }
  }

  return sum;
}

bool Searhone(int n){
  if(n == 1)
    return false;
  else
    return true;
}

C++: 
#include<iostream>
#include<string>
#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;
  }
}