Go: // Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;


int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int tanka[5] = {5, 7, 5, 7, 7};
        string s;
        vector<int> l;
        for (int i = 0; i < n; i++) {
            cin >> s;
            l.push_back(s.length()); 
        }

        for (int i = 0; i < l.size(); i++) {
            int posi = 0;
            vector<int> work(5, 0);
            for (int j = i; j < l.size(); j++) {
                int length = l[j];
                if (work[posi] + length < tanka[posi]) {
                    work[posi] += length; 
                } else if (work[posi] + length == tanka[posi]) {
                    posi++; 
                    if (posi == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                } else {
                    break;
                }
            }
            if (posi == 5) {
                break;
            }
        }
    }

    return 0;
}

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

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        int len[n + 1];
        for (int i = 1; i <= n; ++i) {
            string w;
            cin >> w;
            len[i] = w.length();
        }

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                printf("%d ", cumulativesum[j]);
            }
            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
            cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)goto L;
using namespace std;main(){for(int n,v[50],s,p,c;cin>>n,n;){string t;for(s=0;s<n;)cin>>t,v[++s]=t.size();s=0;L:p=++s;f(5)f(7)f(5)f(7)f(7)cout<<s<<endl;}}

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

#define REP(i, n ,N) for(int i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;

int main(){
	while(1) {
		int n;
		cin >> n;
		if(n==0)break;
		vector<int> word_len(n + 1);
		REP(i, 1, n + 1) {
			string s;
			cin >> s;
			word_len[i] = s.size();
		}

		REP(i, 1, n + 1) {
			int stack = 0;
			int stage = 0;
			REP(j, i, n + 1) {
				if (stage == 0) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 1) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 2) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 3) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 4) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						break;
					}
					if (stack > 7)break;
				}
			}
			if (stage == 5) {
				p(i);
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string.h>
#include<string>
#include<functional>
#include<iomanip>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

int main() {
  int n;
  while (1) {
	cin >> n;
	if (n == 0) {
	  return 0;
	}
	else {
	  vector<int> v;
	  for (int i = 0; i < n; i++) {

		string s;
		cin >> s;
		v.push_back(s.size());
	  }
	  int cnt = 0;
	  int sum = 0;
	  while (1) {
		for (int i = cnt; i < n; i++) {
		  sum = 0;
		  int j = cnt;
		  while (sum < 5) {
			sum += v[j];
			j++;
		  }
		  if (sum != 5) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum != 7) {
			break;
		  }
		  sum = 0;
		  while (sum < 5) {
			sum += v[j];
			j++;
		  }
		  if (sum != 5) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum != 7) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum == 7) {
			goto NEXT;
		  }

		}

		cnt++;
	  }
	NEXT:
	  cout << cnt + 1 << endl;
	}
  }
}