UVa 10132 - File Fragmentation

/* File: 10132.cpp Author: ACboy Date: 2010-3-31 Result: 1A Descripition: UVa 10132 - File Fragmentation */ #include <iostream> using namespace std; char data[150][260]; int cmp(const void * a, const void * b) { char * pa = (char *)a; char * pb = (char *)b; int alen = strlen(pa); int blen = strlen(pb); if (alen == blen) { return strcmp(pa, pb) > 0; } else { return alen > blen; } } int posi[4][4] = { {0, 3, 1, 2}, {3, 0, 1, 2}, {0, 3, 2, 1}, {3, 0, 2, 1} }; int main() { int n; #ifndef ONLINE_JUDGE freopen("10132.txt", "r", stdin); #endif scanf("%d/n", &n); while (n--) { int i, j; int c = 0; char temp[260]; char ans[4][260]; while (gets(temp)) { if (strcmp(temp, "") == 0) { break; } else { strcpy(data[c++], temp); } } qsort(data, c, sizeof(char [260]), cmp); int mid = c / 2; int k = 0; strcpy(ans[k++], data[0]); strcpy(ans[k++], data[mid - 1]); strcpy(ans[k++], data[mid]); strcpy(ans[k++], data[c - 1]); int ok = 0; char t[260]; for (i = 0; i < 4; i++) { char a[260] = ""; char b[260] = ""; for (j = 0; j < 4; j++) { if (j < 2) { strcat(a, ans[posi[i][j]]); } else { strcat(b, ans[posi[i][j]]); } } if (strcmp(a, b) == 0) { ok = 1; strcpy(t, a); break; } } if (ok) { cout << t << endl; } if (n != 0) cout << endl; } return 0; }

你可能感兴趣的:(UVa 10132 - File Fragmentation)