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

int Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() {
	string a;
	while (1) {
		getline(cin, a);
		if (a[0]=='0')break;
		vector<int>s;
		string c="";
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == ' ') { s.push_back(Parse(c)); c = ""; }
			else c += a[b];
		}
		s.push_back(Parse(c));
		int m = 0;
		int n = 0;
		for (int d = 0; d < s.size(); d++) {
			if (s[d] > 9&&s[d]<14)m += 10;
			else if (s[d] > 1)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		cout << n << endl;
		if (m + 10 + n < 22&&n!=0)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	string S;
	while(getline(cin,S)){
		priority_queue<int,vector<int>,greater<int> > pq[2]; pq[0].push(0);
		int cnt = 0;
		for(int i=0;i<S.size();i++){
			if(i==0 || S[i]==' '){
				int n = stoi(&S[i]);
				if(n==0) return 0;
				while(!pq[cnt&1].empty()){
					int pq_c = pq[cnt&1].top(); pq[cnt&1].pop();
					if(pq_c>21) continue;
					if(n==1) pq[(cnt+1)&1].push(pq_c+1), pq[(cnt+1)&1].push(pq_c+11);
					else if(n<10) pq[(cnt+1)&1].push(pq_c+n);
					else pq[(cnt+1)&1].push(pq_c+10);
				}
				cnt++;
			}
		}
		int ans = 0;
		while(!pq[cnt&1].empty()){
			if(pq[cnt&1].top()<=21) ans = max(ans,pq[cnt&1].top());
			pq[cnt&1].pop();
		}
		printf("%d\n",ans);
	}
	return 0;
}

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()
{
//	cut here before submit 
//	freopen("testcase.blackjack", "r", stdin);
	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
//		cout << "sum: " << sum << " ace: " << ace << endl;

		if (ace == 3){
				sum = 21;
		}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++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	string s;
	
	while(1){
		getline(cin,s);
		long long n=0;
		int	count=0;
		if(s=="0")
			break;
		else{
			string a="";
			for(int i=0;i<s.size();i++){
				if(s[i]!=' '){
					a=a+s[i];
				}
				else{
					int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
				}
			}
			int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
			while(count>0){
				if(n+count>21)
					n++;
				else
					n=n+11;
				count-=11;
			}
			
			if(n>21)
				cout<<0<<endl;
			else
				cout<<n<<endl;
		}
	}
	
	
	
	

}

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 <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>
#include <sstream>
using namespace std;
main(){
	int a,r,x;
	string s;
	for(;getline(cin,s);cout<<(r>21?0:a&&r<12?r+10:r)<<endl){
		istringstream is(s);
		for(a=r=0;is>>x;r+=x>9?10:x)if(x==1)a=1;else if(!x)return 0;
	}
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    string s;
    while(1){
        getline(cin,s);
        if(s=="0")break;
        s+=" ";
        vector<string> st;
        string buf="";
        rep(i,s.size()){
            if(s[i]!=' ')buf+=s[i];
            else{
                st.pb(buf);
                buf="";
            }
        }
        
        int score=0;
        int c=0;
        rep(i,st.size()){
            if(st[i]!="1"){
                int num=stoi(st[i]);
                if(10<=num)score+=10;
                else score+=num;
            }
            else{
                score+=1;
                c++;
            }
        }
        rep(i,c){
            if(21-score>=10)score+=10;
        }
        if(score>21)cout<<"0"<<endl;
        else cout<<score<<endl;
    }
}