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 <cstdio>
#include <cstring>

using namespace std;

int main()
{
	char num[25];
	
	while (gets(num) != NULL){
		if (num[0] == '0'){
			break;
		}
		int score = 0;
		int f = 0;
		int i = 0;
		
		int len = strlen(num);
		
		while (i < len){
			if (num[i] == '1' && (num[i + 1] >= '0' && num[i + 1] <= '3')){
				score += 10;
				i += 3;
			}
			else if (num[i] == '1'){
				score++;
				f = 1;
				i += 2;
			}
			else if ('2' <= num[i] && num[i] <= '9'){
				score += (num[i] - '0');
				i += 2;
			}
		}
		if (score > 21){
			score = 0;
		}
		else if (f == 1 && score + 10 <= 21){
			score += 10;
		}
		cout << score << endl;
	}
	return (0);
}

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

int fixNumberOne( int cnt, int a )
{
    if( cnt == 0 )
        return a;
    if( a + 11 <= 22 - cnt )
        return a + 10 + cnt;
    else
        return a + cnt;
}

int main()
{
    int a[128], b[100];
    for( int i = '1'; i < '1' + 9; i++ )
        a[i] = i - '0';
    a['1'+'0'] = 10;
    a['1'+'1'] = 10;
    a['1'+'2'] = 10;
    a['1'+'3'] = 10;

    string str;

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

        str += " ";

        for( int i = 0; i < 100; i++ )
            b[i] = 0;
    
        int j = 0, sum = 0, cnt = 0;
        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] == ' ' )
            {
                if( a[sum] == 1 )
                    cnt++;
                else
                    b[j] = a[sum];
                sum = 0;
                j++;
            }
            else
                sum += str[i];
        }
        sum = 0;
        for( int i = 0; i < 100; i++ )
            if( b[i] != 1 )
                sum += b[i];
        sum = fixNumberOne( cnt, sum );

        if( sum > 21 )
            cout << 0 << endl;
        else
            cout << sum << endl;
    }

    return 0;
}

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

int main(){
  int i,j,n,ans,one;
  string line;
  while(1){
    getline(cin,line);
    if(line == "0") break;
    stringstream sin(line);
    string str;
    ans = 0;
    one = 0;
    while(sin >> str){
      n = atoi(str.c_str()) * 1;
      if(n > 10) n = 10;
      ans += n;
      if(n == 1 && ans <= 11){
	ans += 10;
	one++;
      }

      if(ans > 21){
	if(one > 0){
	  one--;
	  ans -= 10;
	}
	else{
	  ans = 0;
	  break;
	}
      }
    }
    cout << ans << endl;

  }
  return 0;
}

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

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

using namespace std;

vector<string> split(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 s;
	int ans;
	bool flag;
	while(true)
	{
		ans = 0;
		flag = false;
		getline(cin,s);
		vector<string> temp = split(s,' ');
		if(atoi(temp[0].c_str()) == 0) break;

		vector<int> res;
		rep(i,temp.size())
		{
			res.push_back(atoi(temp[i].c_str()));
		}

		sort(res.begin(),res.end(),greater<int>());

		rep(i,res.size())
		{
			if(res[i] == 1)
			{
				if(i == res.size()-1)
				{
					if(ans + 11 > 21) ans += 1;
					else ans += 11;
				}
				else ans += 1;
			}
			else if(res[i] >= 10)
			{
				ans += 10;
			}
			else ans += res[i];

			if(ans > 21)
			{
				flag = true;
			}
		}

		if(flag)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << ans << endl;
		}


	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
int main()
{
	char str[256],*p,*np;
	while(fgets(str,256,stdin),str[0]!='0')
	{
		int s=0,l,c1=0;
		for(p=str;;)
		{
			l=strtol(p,&np,10);
			if(p==np)break;
			p=np;
			s+=(l<10?l:10);
			c1+=(l==1);
		}
		while(s<=11&&c1)s+=10,--c1;
		printf("%d\n",(s>21?0:s));
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int rec(int sum, int one)
{
    if (one == 0 && sum > 21)
        return -1;
    else if (one == 0 && sum <= 21)
        return sum;

    int res = rec(sum + 1, one - 1);
    res = max(res, rec(sum + 11, one - 1));

    return res;
}

bool solve(string &s)
{
    int sum = 0, one = 0;
    int index = 0;

    s += " ";
    while (index < s.size()) {
        int num = 0;

        while (index < s.size()) {
            if ('0' <= s[index] && s[index] <= '9') {
                num *= 10;
                num += (int)(s[index] - '0');
                index++;
            }
            else
                break;
        }

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

    if (sum == 0 && one == 0)
        return false;

    if (sum > 21) {
        cout << 0 << endl;
        return true;
    }
    else if (one == 0) {
        cout << sum << endl;
        return true;
    }
    else {

        int ans = rec(sum, one);
        if (ans >= 0)
            cout << ans << endl;
        else
            cout << 0 << endl;
        return true;
    }
}

int main()
{
    string s;

    while (true) {
        getline(cin, s);
        if (!solve(s))
            break;
    }

    return 0;
}

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

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] = 10;

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

      if(sum+(first*11) <= 21) sum += (first*11);
      else sum += first;

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

  return 0;
}

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

vector<int> check(vector<int>data,int i)
{
  vector<int> ans;
  ans.push_back(0);
  if(data.size()<=i)
    return ans;
  ans.clear();
  vector<int> tmp=check(data,i+1);
  if(data[i]!=1)
    {
      for(int j=0;j<tmp.size();j++)
          if(data[i]+tmp[j]<=21)
              ans.push_back(data[i]+tmp[j]);
    }
  else
    {
      for(int j=0;j<tmp.size();j++)
        {
          if(1+tmp[j]<=21)
            ans.push_back(1+tmp[j]);
          if(11+tmp[j]<=21)
            ans.push_back(11+tmp[j]);
        }
    }

  return ans;

}

int main()
{
  string s;
  for(;getline(cin,s),s!="0";)
    {
      istringstream ss(s);
      vector<int> data;
      int tmp;
      for(;ss>>tmp;)
        {
          if(tmp>10)
            tmp=10;
          data.push_back(tmp);
        }
      vector<int> ans=check(data,0);
      int out=0;
      for(int i=0;i<ans.size();i++)
        {
          out=max(out,ans[i]);
        }
      cout<<out<<endl;
    }
}