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>
using namespace std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L;
        }
      }
    }
    L:cout<<i+1<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,l[45],L[45],a,d[5]={5,7,5,7,7};
string s;
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    a=0;
    for(int i=1;i<=n;i++){
      int x=0,s=i;
      for(int j=i;j<=n;j++){
    if(L[j]-L[s-1]==d[x])x++,s=j+1;
    if(!a&&x==5)a=i,cout<<a<<endl;
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define N 45
using namespace std;
int n,l[N],L[N],ans;
int d[5]={5,7,5,7,7};
string s;

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    ans=0;
    for(int i=1;i<=n;i++){
      int idx=0,s=i;
      for(int j=i;j<=n;j++){
	if(L[j]-L[s-1]==d[idx])idx++,s=j+1;
	if(!ans&&idx==5)ans=i;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	while(cin>>n,n){
		vi in(n);
		rep(i,n){
			string s;
			cin>>s;
			in[i]=s.size();
		}
		int t[5]={5,7,5,7,7};
		rep(i,n){
			vi co(5);
			int now=i;
			int nowc=0;
			while(1){
				co[nowc]+=in[now];
				now++;
				if(co[nowc]==t[nowc])nowc++;
				else if(co[nowc]>t[nowc])break;
				if(nowc==5){
					cout<<i+1<<endl;
					goto end;
				}
			}
		}
		end:;
	}
}

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==4) break;
               a=0;
            }
         }
         cout<< i+1<< endl;
         return 0;
         turai:;
      }

   }

   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)cout<<i+1<<endl;
        }
      }
    }
  }
}

C++: #include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
        }
      }
    }
  }
  return 0;
}

C++: 
#include <iostream>
#include <vector>
#include<stdio.h>
#include <time.h>
#include <string>
using namespace std;

int main() {

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

		string word;
		int *length = new int[n];
		int key[5] = { 5,7,5,7,7 };
		for (int i = 0; i < n; i++) {
			cin >> word;
			length[i] = word.size();
			cout << length[i] << endl;
		}

		int count = 0;
		int section = 0;
		int index = 0;
		int output = 0;
		int start = 0;
		bool found = false;
		while (index != n) {
			index = output;
			output++;

			while (count <= 5) {
				if (key[count] > section) {
					section += length[index++];
				}
				else if (key[count] == section) {
					section = 0;
					count++;
				}
				else {
					break;
				}

				if (count == 5) {
					cout << output << endl;
					found = true;
				}
			}
			count = 0;
			section = 0;
			if (found)
				break;
		}
	}
	return 0;
}

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

int main(){
  int step,flag=0,n,l,x;
  while(1){
    cin >> n;
    if(n==0){break;}
    string w[n];
    for(int i=0;i<n;i++){
      cin >> w[i];
    }
    for(int i=0;i<n-5;i++){
      l=0;
      step=1;
      flag=0;
      x=i;
      while(1){
        if(flag==1){break;}
        l+=w[x].length();
        switch(step){
          case 1:
          if(l>5){flag=1;}
          else if(l==5){step++;}
          break;
          case 2:
          if(l>12){flag=1;}
          else if(l==12){step++;}
          break;
          case 3:
          if(l>17){flag=1;}
          else if(l==17){step++;}
          break;
          case 4:
          if(l>24){flag=1;}
          else if(l==24){step++;}
          break;
          case 5:
          if(l>31){flag=1;}
          else if(l==31){flag=2;}
          break;
        }
        if(flag==2){break;}
        x++;
      }
      if(flag==2){x=i+1;break;}
    }
    if(flag==2){cout << x << endl;}
  }
  return 0;
}