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 <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

const int mod = 1e5;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;
 
int main(){
    int n;
    
    while(cin >> n){
        if (n == 0) break;
        
        vector<long long> imos(101010);
        
        rep(i,n){
            string s1, s2;
            cin >> s1 >> s2;
            
            int start_h1 = ((s1[0] - '0') * 10 + (s1[1] - '0')) * 3600; 
            int start_m1 =  ((s1[3] - '0') * 10 + (s1[4] - '0')) * 60;
            int start_s1 = (s1[6] - '0') * 10 + s1[7] - '0';
            int start_time =  start_h1 + start_m1 + start_s1;
            
            int arrival_h2 = ((s2[0] - '0') * 10 + (s2[1] - '0')) * 3600; 
            int arrival_m2 =  ((s2[3] - '0') * 10 + (s2[4] - '0')) * 60;
            int arrival_s2 = (s2[6] - '0') * 10 + s2[7] - '0';
            int arrival_time =  arrival_h2 + arrival_m2 + arrival_s2;
            
            for (int j = start_time; j < arrival_time; j++) imos[j]++;
        }

        long long ans = 0;
        
        for (int i = 0; i <86400; i++) ans = max(ans, imos[i]);
        cout << ans << endl;
        
    }
}

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

#define MAX 24*60*60

int main(){

  int train[MAX];
  int N;

  while(1){
    cin >> N;
     if(N == 0) break;
     int ans = 0;
     for(int i = 0 ; i < MAX ; i++){
       train[i] = 0;
     }    


    int h1,m1,s1,h2,m2,s2;
    char tmp;
    for(int i = 0; i < N ; i++){
    
      cin  >> h1 >> tmp >> m1 >> tmp >> s1 >> h2 >> tmp >> m2 >> tmp >> s2;
      // cout << h1 << " " << m1 << " " << s1 << " " << h2 << tmp << m2 << tmp << s2 <<endl;

      //列車を増やすとき
      if(train[s1 + 60*m1 + 60*60*h1] == 0){
	ans++;
	for(int i = 0 ; i < s1 + 60*m1 + 60*60*h1 ;i++){
	  train[i]++;
	} 
	for(int i = s2 + 60*m2 + 60*60*h2 ; i < MAX ;i++){
	  train[i]++;
	} 
      } 
      //足りているとき
      else{
	for(int i =  s1 + 60*m1 + 60*60*h1 ; i <= s2 + 60*m2 + 60*60*h2-1 ;i++){
	  if(train[i] > 0) train[i]--;
	} 
      }
    }
    cout << ans << endl;
  }  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#define N 10000
using namespace std;
int Change(string);
int Change_sup(string);
struct data{
  int s,g;
  bool operator<(const data & right)const{
    if(s!=right.s) return s<right.s;
    return g<right.g;
  }
};
int main(){
  int n,flag[N],com,cnt,i,j;
  string ins,ing;
  struct data d[N];
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> ins >> ing;
      d[i].s=Change(ins);
      d[i].g=Change(ing);
      flag[i]=0;
    }
    sort(d,d+n);
    cnt=0;
    for(i=0;i<n;i++){
      if(flag[i]==0){
	flag[i]=1;
	cnt++;
	com=d[i].g;
	for(j=i+1;j<n;j++){
	  if(com<=d[j].s&&flag[j]==0){
	    flag[j]=1;
	    com=d[j].g;
	  }
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
int Change(string str){
  int r;
  string a,b,c;
  a=str.substr(0,2);
  b=str.substr(3,2);
  c=str.substr(6,2);
  r=Change_sup(a+b+c);
  return r;
}
int Change_sup(string str){
  int len=str.size(),x=1,ret=0,i=0;
  while(len){
    ret=ret*x+(str[i]-'0');
    x=10;
    i++;
    len--;
  }
  return ret;
}

C++: #include<bits/stdc++.h>

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;
typedef std::vector<PII> VPII;

int n;
VPII v;
int main() {
    int h, m, s;
    while(std::cin >> n, n != 0) {
        v.clear();
        REP(i, n) {
            scanf("%d:%d:%d", &h, &m, &s);
            v.pb(mp(h*3600+m*60+s, 1));
            scanf("%d:%d:%d", &h, &m, &s);
            v.pb(mp(h*3600+m*60+s, -1));
        }
        SORT(v);

        int res = 0, ans = 0;
        for(auto t: v) {
            res += t.snd;
            ans = std::max(ans, res);
        }
        std::cout << ans << std::endl;
    }
}