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++: 1#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'){
    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]);

    int one = 11*a[1];
    while(res+one > 21 && one != a[1]){
      one -= 10;
    }
    //    printf("%d\n", res+one);
    res += one;
    if(res > 21) res = 0;

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

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<stdio.h>
#include<iostream>
using namespace std;

int main(){

int n,s=0;int A=0;
while(1){
scanf("%d",&n);
if(n==0)break;
s+=n;
while(cin>>n){
	
if(n>1&&n<11)s+=n;
else if(n>10)s+=10;
else if(n==1){s+=1;A++;}
}
if(s>=22)printf("0\n");


else {
	if(A>0){
	for(int i=0;i<A;i++)
		if(s+10<=21)s+=10;
	
	}
	
	
}
	

printf("%d\n",s);s=0;A=0;
}
return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)

void split( vector<int>& vi, string in ) {
    int i=0;
    while( i < in.length() ) {
        int x = 0;
        while( i < in.length() && in[i]!=' ' ) {
            x *= 10;
            x += in[i]-'0';
            i++;
        }
        vi.push_back(x);
        i++;
    }
}

int main(){
    string in;
    while( getline(cin, in), !(in.length()==1 && in[0]=='0') ) {
        vector<int> vi;
        split( vi, in );
        int score=0, one=0;
        rep(i, vi.size()) {
            if( vi[i] == 1 ) {
                one++;
                score += 1;
            } else {
                score += min(10, vi[i]);
            }
        }
        while( one && score+10<=21 ) {
            score += 10;
            one--;
        }
        cout << (score<=21 ? score : 0) << endl;
    }
    return 0;
}

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


int main(){
  int fla=0,cou,sum,b;
  char a;
  while(1){
    sum=0;
    cou=0;
    while(1){
      scanf("%d%c",&b,&a);
      if(b>=10)sum+=10;
      else sum+=b;
      if(b==1)cou++;
      if(a=='\n')break;
    }
    if(sum==0)break;

    for(int i=0;i<cou;i++){
      if(21-sum>=10)sum+=10;
      else break;
    }
    if(sum>21)cout << "0"<<endl;
    else cout << sum << endl;
  }
  return 0;
}

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

int main()
{
  string str;

  while (1){
    getline(cin, str);
    if (str[0] == '0') break;

    int sum = 0;
    int cnt = 0;

    for (int i = 0; i < str.size(); i++){
      if (str[i] == '1' && '0' <= str[i + 1] && str[i + 1] <= '3'){
        sum += 10;
        i++;
        continue;
      }
      if (str[i] == '1') cnt++;
      if (str[i] != ' ') sum += (str[i] - '0');
    }


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

   cout << sum << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  while(getline(cin,s) && s!="0")
    {
      int lowerten=0;
      int one=0;
      int score=0;
      int lastscore=0;
      string num="";
      //cout << int(s.size()) << endl;
      for(int i=0;i<int(s.size());i++)
	{
	  if(s[i]!=' ')
	    {
	      num+=s[i];
	    }
	  if(s[i]==' ' || i==int(s.size()-1))
	    {
	      int getnum=stoi(num);
	      if(getnum>=10) score+=10;
	      else if(getnum==1) one++;
	      else score+=getnum;
	      num="";
	    }
	}
      for(int i=0;i<=one;i++)
	{
	  int addscore=11*i+1*(one-i);
	  if(score+addscore>21)
	    {
	      continue;
	    }
	  else
	    {
	      lastscore=max(lastscore,score+addscore);
	    }
	}
      if(score>21)
	{
	  cout << 0 << endl;
	}
      else
	{
	  cout << lastscore << endl;
	}
    }
  return 0;
}