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 <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

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

using namespace std;
/** Problem0169 : Blackjack **/
int main()
{
	int ans, one, t;
	string s;
	
	while (!cin.eof()) {
		getline(cin, s);
		if (s == "0") break;
		stringstream ss(s);
		
		ans=0; one=0;
		while (!ss.eof()) {
			ss >> t;
			if (2 <= t && t < 10)
				ans += t;
			else if (t == 1) {
				one++;
				ans+=11;
			} else {
				ans+=10;
			}
		}
		
		while (ans>21 && one>0) {
			one--;
			ans-=10;
		}
		
		if (ans > 21) ans=0;
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
  cin >> noskipws;
  while(true)
  {
    int cards[21];
    int card_num;
    int ace_num = 0;   //  エースがあるかどうか
    for (card_num = 0; ; card_num++)
    {
      if ( card_num == 22 )
      {
        int dummy;
        char ws;
        bool b = true;
        while (b)
        {
          cin >> dummy >> ws;
          if ( ws != ' ' )
          {
            b = false;
          }
        }
        break;
      }
      cin >> cards[card_num];
      if ( cards[card_num] == 0 ) return 0;
      if ( cards[card_num] == 1 ) ace_num++;
      char ws;
      cin >> ws;
      if ( ws != ' ' )
      {
        card_num++;
        break;
      }
    }

    int point = 0;
    for (int i=0; i<card_num; i++)
    {
      if ( cards[i] < 10 )
      {
        point += cards[i];
      }
      else
      {
        point += 10;
      }
    }

    while ( ace_num > 0 && point <= 11 )
    {
      point += 10;
      ace_num--;
    }
    if ( point > 21 )
    {
      point = 0;
    }

    cout << point << endl;

  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int power(int n)
{
???int num=1;
???for(int i=0;i<n;i++)num*=10;
???return num;
}
int serch(int sum,int n)
{
???if(sum>21)return 0;
???else if(n==0)return sum;
???else return max(serch(sum+11,n-1),serch(sum+1,n-1));
}
int main()
{
???string str;
???while(getline(cin,str)){
??????if(str[0]=='0')break;
??????int card[1000]={},co=0,point=0;
??????for(int i=0;;i++){
?????????if(str[i]==' '||str[i]=='\0'){
????????????for(int j=point;j<i;j++)card[co]+=(str[j]-'0')*power(i-1-j);
????????????co++;point=i+1;
?????????}
?????????if(str[i]=='\0')break;
??????}
??????int cou=0,sum=0;
??????for(int i=0;i<co;i++){
?????????if(card[i]==1)cou++;
?????????else if(card[i]<10)sum+=card[i];
?????????else sum+=10;
??????}
??????cout<<serch(sum,cou)<<endl;
???}
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char buf[400];
	int checkTable[14],tmp,sum;

	while(true){
		fgets(buf,400,stdin);
		if(buf[0] == '0')break;

		for(int i= 1; i <= 13; i++){
			checkTable[i] = 0;
		}

		sum = tmp = 0;
		for(int i=0; buf[i] != '\n' && buf[i] != '\0'; i++){
			if(buf[i] >= '0' && buf[i] <= '9'){
				tmp = 10*tmp + (buf[i] - '0');

				if(buf[i+1] == '\n' || buf[i] == '\0'){
					checkTable[tmp]++;
				}
			}else{
				checkTable[tmp]++;
				tmp = 0;
			}
		}

		for(int i=10; i <= 13; i++)sum += 10*checkTable[i];
		for(int i= 9; i >= 2; i--)sum += i*checkTable[i];

		if(sum > 21)printf("0\n");
		else{
			if(checkTable[1] == 0)printf("%d\n",sum);
			else{
				if(sum + checkTable[1] > 21){
					printf("0\n");
				}else if(sum >= 11){
					printf("%d\n",sum+checkTable[1]);
				}else{
					int zero,one;

					zero = sum + checkTable[1];
					one = sum + 11 + checkTable[1]-1;
					if(one > 21)one = 0;

					sum = max(zero,one);

					printf("%d\n",sum);
				}
			}
		}
	}

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int n,c,m;
  char w;
  while(1){
    m=0;
    c=0;
    while(1){
      scanf("%d%c",&n,&w);
      if(n==0)break;
	if(n==1){
	  m+=1;
	  c+=11;
	}
	else if(n>10)c+=10;
	else c+=n;
      if(w=='\n')break;
    }

    while(m!=0){
      if(c>21){
	m--;
	c-=10;
      }
      else break;
    }
    if(c<22)cout << c << endl;
    else cout<< "0"<<endl;
  }
  return 0;
}

C++: #include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

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

using namespace std;
/** Problem0169 : Blackjack **/
int main()
{
	int ans, one, t;
	string s;
	
	while (!cin.eof()) {
		getline(cin, s);
		if (s == "0") break;
		stringstream ss(s);
		ans=0; one=0;
		while (!ss.eof()) {
			ss >> t;
			ans += t;
			if (t == 1) {
				one++;
				ans+=10;
			}
			
			if (ans > 21 && one>0) {
				ans -= 10;
				one--;
			}
		}
		if (ans > 21) ans=0;
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

vector<int> nums;

vector<string> split(string str, string delim)
{
	int pos = 0;
	vector<string> vec;
	while((pos=str.find_first_of(delim)) != str.npos)
	{
		if(pos > 0)
		{
			vec.push_back(str.substr(0, pos));
		}
		str = str.substr(pos + 1);
	}

	if(str.length() > 0)
	{
		vec.push_back(str);
	}

	return vec;
}

void solve()
{
	int sum = 0;
	int c = 0;
	for(int i=0; i<nums.size(); i++)
	{
		if(nums[i]>=10) sum += 10;
		else if(nums[i] != 1) sum += nums[i];
		else sum += 11, c++; 
	}

	for(int i=0; i<c; i++)
	{
		if(sum > 21) sum -= 10;
		else break;
	}
	sum = sum > 21 ? 0 : sum;
	cout << sum << endl;
}

int main(int argc, char** argv)
{
	string s;
	vector<string> vec;
	while(getline(cin, s) && s!="0")
	{
		vec = split(s, " ");
		nums.clear();
		for(int i=0; i<vec.size(); i++)
		{
			nums.push_back(atoi(vec[i].c_str()));
		}
		solve();
	}
}

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

int calc(int card[5], int score=0, int cnt=0) {
  static int max;
  if(cnt == 0) max = -1;

  if(cnt == 5) {
    if(score > 21) score = 0;
    if(score > max) max = score;
    return 0;
  }

  if(card[cnt] == 1) {
    calc(card, score+1, cnt+1);
    calc(card, score+11, cnt+1);
  } else if(card[cnt] > 10) {
    calc(card, score+10, cnt+1);
  } else {
    calc(card, score+card[cnt], cnt+1);
  }

  if(cnt == 0) return max;
}

int main() {
  while(1) {
    string str;
    getline(cin, str);
    if(str == "0") break;

    stringstream sin;
    sin << str;
    int card[5];
    fill(&card[0], &card[4]+1, 0);
    int num;
    for(int i = 0; i < 5; i++) {
      if(!(sin >> card[i])) {
	num = i;
	break;
      }
      if(i+1 == 5) {
	num = 5;
	break;
      }
    }

    cout << calc(card) << endl;
  }
  return 0;
}

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;
		score = 0;
		f = 0;
	}
	
	return (0);
}