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<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 <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	string str = "";
	vector < vector <int> > hand;

	while (getline (cin, str ) ){
		if (str.length() == 1 && str[0] == '0'){
			break;
		} // end if

		int n;
		stringstream ss(str);
		vector <int> card;

		while (ss >> n){
			card.push_back (n );
		} // end while

		hand.push_back(card );

	} // end loop

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

		vector <int>::iterator it = hand[i].begin();
		int ace = 0;
		int sum = 0;

		for (; it != hand[i].end(); ++it ){
			if ((*it) == 1 ){
				++ace;
			}else if ((*it) >= 10){
				sum += 10;
			}else{
				sum += (*it);
			} // end if
		} // end for

		if (ace >= 4){
			sum += ace;
		}else if (ace == 3){
			if (sum == 0){
				sum = 21;
			}else{
				sum += 3;
			} // end if
		}else if (ace == 2){
			if (sum <= 9){
				sum += 12;
			}else{
				sum += 2;
			} // end if
		}else if (ace == 1){
			if (sum <= 10){
				sum += 11;
			}else{
				sum += 1;
			} // end if
		} // end if
		
		if (sum <= 21){
 			cout << sum << endl;
		}else{
			cout << '0' << endl;
		} // end if

	} // end for

	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[30];

	while( cin.getline( str, 30 ) && 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 > 21 ) answer = 0;
		else if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 > 21 ) break;
				answer += 10;
			}
		}
		cout << answer << endl;
	}
	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,k;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    
    while(ss>>x){
      si=v.size();
      vector<int> n;
      for(i=0;i<si;i++){
	
	if(x==1){
	  k=v[i];
	  n.push_back(k+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 <vector>
#include <algorithm>	
#include <numeric>
#include <sstream>

#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;


int main()
{
	string str = "";
	
	while (getline (cin, str ) && str != "0" ){
		stringstream ss (str );
		vector <int> hand;
		int n;
		int ace = 0;
		while (ss >> n ){
			if (n == 1 )
				ace++;
			if (n > 10 )
				n = 10;
			hand.push_back (n );
		} // end while
		int sum = accumulate (ALL (hand ), 0 );
		int res = 0;
		if (ace == 0 && sum > 21 ){
			res = 0;
		}else if (ace == 0 && sum <= 21 ){
			res = sum;
		}else if (ace && sum > 21 ){
			res = 0;
		}else if (ace && sum == 21 ){
			res = sum;
		}else{
			res = sum;
			for (int i = 1; i <= ace; i++ ){
					int curr = sum + 10*i;
				if (curr <= 21 ){
					res = max (res, curr );
				} // end 
		 	} // end for
		} // end if
		cout << res << endl;	
	} // end loop
		
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	for(string line; getline(cin, line) && line[0] != '0';)
	{
		int points = 0, one = 0;
		
		istringstream iss(line);
		for(string word; iss >> word; )
		{
			int tmp = atoi(word.c_str());
			
			if(tmp == 1) one++;
			else points += (tmp < 10 ? tmp : 10);
		}
		
		int total = 0;
		for(int i = 0; i <= one; i++)
		{
			int tmp = points + i * 10 + one;
			
			if(tmp <= 21) chmax(total, tmp);
		}
		
		cout << (total <= 21 ? total : 0) << endl;
	}
}

C++: //53
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main(){
  for(string s;getline(cin,s),s!="0";){
    stringstream ss(s);
    int p=0,o=0;
    for(int c;ss>>c;){
      if(c==1){
	o++;
      }else if(c>=10){
	p+=10;
      }else{
	p+=c;
      }
    }
    while(o&&p+11+o-1<=21){
      p+=11;
      o--;
    }
    p+=o;
    cout<<((p>21)?0:p)<<endl;
  }
  return 0;
}

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