Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		accum := make([]int, 86401)
		for i := 0; i < n; i++ {
			s, e := io.Next(), io.Next()
			hs, _ := strconv.Atoi(s[:2])
			ms, _ := strconv.Atoi(s[3:5])
			ss, _ := strconv.Atoi(s[6:8])
			accum[hs*60*60+ms*60+ss]++
			he, _ := strconv.Atoi(e[:2])
			me, _ := strconv.Atoi(e[3:5])
			se, _ := strconv.Atoi(e[6:8])
			accum[he*60*60+me*60+se]--
		}
		ans := 0
		for i := 1; i < 86401; i++ {
			accum[i] += accum[i-1]
			ans = intMax(accum[i], ans)
		}
		io.Println(ans)
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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

#define rep(i,x,y) for(int (i)=(x);i<(y);i++)

typedef struct{
  int hour;
  int minute;
  int second;
}Train;

int main()
{
  while(true){
    int n;
    cin>>n;
    if(n==0){
      break;
    }

    string str1;
    string str2;
    vector<int> sh,sm,ss,eh,em,es;
    rep(i,0,n){
      cin>>str1>>str2;
      sh.emplace_back(stoi(str1.substr(0,2)));
      sm.emplace_back(stoi(str1.substr(3,2)));
      ss.emplace_back(stoi(str1.substr(6,2)));
      eh.emplace_back(stoi(str2.substr(0,2)));
      em.emplace_back(stoi(str2.substr(3,2)));
      es.emplace_back(stoi(str2.substr(6,2)));
    }

    for(int i=n-1;i>=0;i--){
      for(int j=0;j<i;j++){
        if(sh[j]>sh[j+1]){
          swap(sh[j],sh[j+1]);
          swap(sm[j],sm[j+1]);
          swap(ss[j],ss[j+1]);
          swap(eh[j],eh[j+1]);
          swap(em[j],em[j+1]);
          swap(es[j],es[j+1]);
          break;
        }
        if(sh[j]==sh[j+1]&&sm[j]>sm[j+1]){
          swap(sh[j],sh[j+1]);
          swap(sm[j],sm[j+1]);
          swap(ss[j],ss[j+1]);
          swap(eh[j],eh[j+1]);
          swap(em[j],em[j+1]);
          swap(es[j],es[j+1]);
          break;
        }
        if(sh[i]==sh[i+1]&&sm[j]==sm[j+1]&&ss[i]>ss[j+1]){
          swap(sh[j],sh[j+1]);
          swap(sm[j],sm[j+1]);
          swap(ss[j],ss[j+1]);
          swap(eh[j],eh[j+1]);
          swap(em[j],em[j+1]);
          swap(es[j],es[j+1]);
          break;
        }
      }
    }

    vector<Train> trains;
    Train t={0,0,0};
    trains.push_back(t);

    rep(i,0,n){
      bool flag=false;
      int size=trains.size();
      rep(j,0,size){
        if((sh[i]>trains[j].hour)||(sh[i]==trains[j].hour&&sm[i]>trains[j].minute)||(sh[i]==trains[j].hour&&sm[i]==trains[j].minute&&ss[i]>=trains[j].second)){
          trains[j].hour=eh[i];
          trains[j].minute=em[i];
          trains[j].second=es[i];
          flag=true;
          break;
        }
      }
      if(flag==false){
        t.hour=eh[i];
        t.minute=em[i];
        t.second=es[i];
        trains.push_back(t);
      }
    }

    cout<<trains.size()<<endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
static const int N = 10000;
int Change(string);
struct data{
  int sh,sm,ss,eh,em,es;
  bool operator<(const data& right)const{
    if(sh!=right.sh) return sh<right.sh;
    if(sm!=right.sm) return sm<right.sm;
    return ss<right.ss;
  }
};
int main(){
  int n,cnt,check[N],ok,flag,Max,i,j;
  int comh,comm,coms;
  string start[N],end[N],sub;
  while(1){
    cin >> n;
    vector<data> V(n);
    cnt=0;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> start[i] >> end[i];
      check[i]=-1;
      sub=start[i].substr(0,2);
      V[i].sh=Change(sub);
      sub=start[i].substr(3,2);
      V[i].sm=Change(sub);
      sub=start[i].substr(6,2);
      V[i].ss=Change(sub);
      sub=end[i].substr(0,2);
      V[i].eh=Change(sub);
      sub=end[i].substr(3,2);
      V[i].em=Change(sub);
      sub=end[i].substr(6,2);
      V[i].es=Change(sub);
    }
    sort(V.begin(),V.end());
    /*  for(i=0;i<n;i++) cout << V[i].sh << ' ' << V[i].sm << ' ' << V[i].ss << ' ' << V[i].eh << ' ' << V[i].em << ' ' << V[i].es << ' ' << check[i] << endl;*/
    for(i=0;i<n;i++){
      if(check[i]==-1){
	check[i]=i;
	comh=V[i].eh;
	comm=V[i].em;
	coms=V[i].es;
	for(j=i+1;j<n;j++){
	  if(check[j]==-1){
	    ok=0;
	    if(comh==V[j].sh){
	      if(comm==V[j].sm){
		if(coms<=V[j].ss) ok=1;
	      }
	      else if(comm<V[j].sm) ok=1;
	    }
	    else if(comh<V[j].sh) ok=1;
	    if(ok==1){
	      check[j]=i;
	      comh=V[j].eh;
	      comm=V[j].em;
	      coms=V[j].es;
	    }
	  }
	}
      }
    }
    /*    for(i=0;i<n;i++) cout << V[i].sh << ' ' << V[i].sm << ' ' << V[i].ss << ' ' << V[i].eh << ' ' << V[i].em << ' ' << V[i].es << ' ' << check[i] << endl;*/
    Max=0;
    for(i=0;i<n;i++){
      Max=max(Max,check[i]);
    }
    cout << Max+1 << endl;
  }
  return 0;
}
int Change(string sub){
  int ret=0,x=1,i;
  for(i=0;i<2;i++){
    ret=ret*x+(sub[i]-'0');
    x=10;
  }
  return ret;
}

C++: #include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
main(){
	int N,i,h,m,d,r,R;
	for(;scanf("%d",&N),N;printf("%d\n",m)){
		vector<pair<int,int> >v;
		for(i=0;i<N*2;i++){
			scanf("%d:%d:%d",&h,&m,&d);
			v.push_back(make_pair(h*3600+m*60+d,i%2?-1:1));
		}
		sort(v.begin(),v.end());
		for(h=m=i=0;i<N*2;i++){
			h+=v[i].second;
			if(m<h)m=h;
		}
	}
}

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

int main()
{
    int n;

    cin >> n;

    int ans = 0;
    while (n != 0)
    {
        vector<int> retime(360000);

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

            int h, m, s;
            int entime;
            int detime;

            scanf("%d:%d:%d", &h, &m, &s);
            retime[h * 60 * 60 + m * 60 + s]++;
            scanf("%d:%d:%d", &h, &m, &s);
            retime[h * 60 * 60 + m * 60 + s]--;
        }

        for (int i = 1; i < 360000; i++)
        {
            retime[i] += retime[i - 1];
        }

        ans = *max_element(retime.begin(), retime.end());

        cout << ans << endl;
        ans = 0;
        cin >> n;
    }
}