POJ-3080 Blue Jeans 暴力

直接暴力

代码如下:

#include <cstring>

#include <cstdlib>

#include <cstdio>

#include <algorithm>

#include <map>

#include <string>

#include <iostream>

using namespace std;



int N;



string ans;



map<string, int>mp[15]; 

map<string, int> :: iterator it;



int main()

{

    int T;

    char s[65], t[65], rec;

    scanf("%d", &T);

    while (T--) {

        scanf("%d", &N);

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

            scanf("%s", s);

            for (int j = 0; j < 60; ++j) {

                for (int k = j; k < 60; ++k) {

                    rec = s[k+1];

                    s[k+1] = '\0';

                    mp[i][s+j] = 1;

                    s[k+1] = rec; 

                }

            }

        }    

        int flag, Max = -1;

        for (it = mp[0].begin(); it != mp[0].end(); ++it) {

            flag = 0;

            for (int i = 1; i < N; ++i) {

                if (!mp[i].count(it->first)) {

                    flag =1;

                    break;

                }

            }

            if (!flag) {

                if (Max < (int)(it->first).size()) {

                    ans = it->first;

                    Max = (int)(it->first).length(); 

                }

            }

        }

        if (Max >= 3) {

            cout << ans << endl;

        }

        else {

            cout << "no significant commonalities" << endl;

        }

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

            mp[i].clear();

        }

    }

    return 0;    

}

你可能感兴趣的:(poj)