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

int card[50];

int main(void){
	while(1){
		string str;
		getline(cin,str);
		stringstream ss(str);
		vector<string> v;
		string buffer;
		int sum=0,cnt=0;
		while(getline(ss,buffer,' '))v.push_back(buffer);
		if(v[0]=="0")break;
		for(int i=0;i<v.size();i++){
			stringstream iss(v[i]);
			iss >> card[i];
			if(card[i]==1)cnt++;
			if(card[i]>=2 && card[i]<=9)sum+=card[i];
			if(card[i]>=10)sum+=10;
		}
		if(sum>21)printf("0\n");
		else{
			int maxp=0;
			for(int i=0;i<=cnt;i++){
				int p=sum+1*i+11*(cnt-i);
				if(p>21)continue;
				maxp=max(maxp,p);
			}
			printf("%d\n",maxp);
		}
	}
	return 0;
}

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

int main(){
  

  char n,m;
  int a,c = 0,sum = 0,sw = 0;

  while(1){  
    while(1){
      scanf("%c",&n);
      if(n == '0' && sw == 0) break;
      if(n != ' ' && sw != 1 && n != '\n'){
	sw = 1;
	a = atoi(&n);
	continue;
      }
      else if(n!=' ' && sw == 1 && n !='\n'){
	sw = 0;
	a = a * 10 + atoi(&n);
	continue;
      }
      else if(n == ' '){
	sw = 0;
      }
  
      cout << "a = " << a << endl;    

      if(a >= 2 && a <= 9) sum += a;
      if(a >= 10 && a <= 13 ) sum += 10;
      if(a == 1) {
	sum += a;
	c++;
      }
      if(n == '\n') break; 
    }
    if(n == '0' && sw == 0) break;

    for(int j = 0;j < c; j++){
      if(sum + 10 < 21) sum += 10;
      else break;
    }

    if(sum <= 21) cout << sum << endl;
    else cout << '0' << endl;
    c=0;
    sum=0;
    sw = 0;
     
  }
 
}

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

int main(){
    string str;
    while(getline(cin, str)){
        stringstream ss;
        vector<int> hand;
        if(str == "0") break;
        int begin = 0;
        int point = 0;
        int one = 0;
        bool isbust = false;
        for(int i=0; i<str.size(); i++){
            if(str[i] == ' ' || i == str.size()-1){
                int tmp;
                ss << str.substr(begin, i-begin+1);
                ss >> tmp;
                if(tmp < 10){
                    hand.push_back(tmp);
                }else{
                    hand.push_back(10);
                }
                begin = i + 1;
            }
        }
        for(int i=0; i<hand.size(); i++){
            if(hand[i] == 1){
                one++;
            }else{
                point += hand[i];
            }
        }
        point += one*11;
        while(one--&&point>21){
            point -= 10;
        }
        if(point > 21){
            cout << "0" << endl;
        }else{
            cout << point << endl;
        }
    }
    return 0;
}

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

using namespace std;

			    
int main() {

  vector<int> hand;

  int sum;
  int one;
  char buf[100000];
  
  char* tp;


  while(fgets(buf,sizeof(buf),stdin)!=NULL) {

    buf[strlen(buf)-1]='\0';

    hand.clear();

    tp=strtok(buf," ");

    if(tp[0]=='1') {

      if(tp[1]!='\0') hand.push_back(10+(tp[1]-'0'));

      else hand.push_back(1);

    }

    else hand.push_back(tp[0]-'0');

    if(hand[0]==0) break;

    while(tp!=NULL) {

      tp=strtok(NULL," ");

      if(tp!=NULL) {

	if(tp[0]=='1') {

	  if(tp[1]!='\0') hand.push_back(10+(tp[1]-'0'));

	  else hand.push_back(1);

	}

	else hand.push_back(tp[0]-'0');

      }

    }

    //for(int i=0;i<hand.size();i++) cout << hand[i] << " ";
    //cout << endl;
    sum=one=0;

    for(int i=0;i<hand.size();i++) {

      if(hand[i]==1) one++;

      else if(hand[i]>=10 && hand[i]<=13) sum+=10;

      else sum+=hand[i];

    }

    for(int i=0;i<one;i++) sum+=11;

    for(int i=0;i<one;i++) {

      if(sum>21) sum-=10;

    }

    if(sum>21) sum=0;

    cout << sum << endl;
    
  }

  return 0;

}

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

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	char str[90];

	while( cin.getline( str, 90 ) && strcmp( str, "0" ) != 0 ){
		char *t;
		data.clear();
		t = strtok( str, " " );
		data.push_back( atoi( t ) );
		while( ( ( t = strtok( NULL, " " ) ) != NULL ) ){
			data.push_back( atoi( t ) );
		}

		int answer;
		int count;

		answer = 0;
		count = 0;

		for( int i = 0;i < data.size();i++ ){
			if( data[i] >= 10 ) answer += 10;
			else answer += data[i];
			if( data[i] == 1 ) count++;
		}
		if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 <= 21 ) answer += 10;
			}
		}
		
		if( answer > 21 ) answer = 0;
		cout << answer << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	string s;
	while(getline(cin,s)&&s!="0"){
		s.push_back(' ');
		int one=0;
		int sum=0;
		
		string a;
		for(int i=0;i<s.size();i++){
			if(s[i]==' '){
				int b=to_string(a);
				if(b==1)one++;
				else if(b>10)sum+=10;
				else sum+=b;
				}
			else a.push_back(s[i]);
			}
			
		int dp[114][23]={};
		dp[0][max(22,sum)]=1;
		for(int i=1;i<=one;i++){
			for(int j=0;j<22;j++){
				dp[i][j+1]=dp[i][j];
				dp[i][max(22,j+11)]=dp[i][j];
				}
			}
			
		int ans=0;
		for(int i=0;i<22;i++){
			if(dp[one][i])ans=i;
			}		
		cout<<ans<<endl;	
		}
	return 0;
	}

C++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

vector<int> split(string delim,string str){
	vector<int> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				int num = atoi(str.substr(i,j-1).c_str());
				if(str.substr(i,j-1).size() >0 ) res.push_back(num);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

void dfs(const vector<int>& data, int i,int sum,int* res){

	if(i==data.size()){
		if(sum <=21 && abs(*res-21) > abs(sum-21)){
			*res=sum;
		}
		return;
	}
	if(data[i] == 1){
		dfs(data,i+1,sum+1,res);
		dfs(data,i+1,sum+11,res);
	}
	else if(2 <= data[i] && data[i] <= 9){
		dfs(data,i+1,sum+data[i],res);
	}
	else{
		dfs(data,i+1,sum+10,res);
	}
}

int main(){
	string str;
	while(getline(cin,str)){
		vector<int> data = split(" ",str);
		if(data.size()==1 && data[0]==0) break;
		int res=10000;
		dfs(data,0,0,&res);
		printf("%d\n",res == 10000 ? 0 : res);
	}
}