uva 11732 - strcmp() Anyone?

一直SubmissionErr,先放在这吧
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define INF 0x3fffffff
#define inf -0x3f3f3f3f
#define N 200010
#define M 4000010
#define LL long long
#define mod 20071027

using namespace std;

int sz, cnt;
int arr[M][26], sum[M];
char str[1010];

void init(){
    cnt = 0;
    sz = 1;
    memset(arr[0], 0, sizeof(arr[0]));
    sum[0] = 0;
}

int idx(char c){
    return c - 'a';
}

void insert(){
    int u = 0;
    for(int i = 0; str[i]; ++i){
        int c = idx(str[i]);
        cnt += sum[u];
        ++ sum[u];
        if(! arr[u][c]){
            memset(arr[sz], 0, sizeof(arr[sz]));
            sum[sz] = 0;
            arr[u][c] = sz ++;
        }
        u = arr[u][c];
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    int n, t = 0;
    while(scanf("%d", &n) != EOF){
        if(! n) break;
        init();
        for(int i = 0; i < n; ++ i){
            scanf("%s", str);
            insert();
        }
        printf("Case %d: %d\n", ++ t, cnt);
    }
    return 0;
}

你可能感兴趣的:(uva)