範例程式碼 uva11157

//uva11157
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

main(){
	//t:test case//n:number of stone//d:river width
	int t, n, d, b, maxnum;
	int i, j, k;
	int stone[220];
	char ch;
	cin >> t;
	for (i = 0; t>0; t--) {
        cin >> n >> d;
        stone[0] = 0;
        stone[1] = d;
        for (j = 0, k = 2;j < n; j++){
            cin >> ch;
            cin.ignore();
            cin >> b;
            stone[k] = b;
            k++;
            if (ch == 'B'){
                stone[k] = b;
                k++;
            }
        }
        sort(stone, stone+k);
        maxnum = 0;
        if (n == 0)
            maxnum = d;
        else{
            for (j = 2; j < k; j += 2)
                maxnum = max(maxnum, stone[j] - stone[j - 2]);
            for (j = 3; j < k; j += 2)
                maxnum = max(maxnum, stone[j] - stone[j - 2]);
        }
        cout << "Case " << ++i << ": " << maxnum << endl;
	}
}