UVA10391 Compound Words

题意:在一堆单词里找满足有其他两个单词复合而来的单词。

思路:直接找。

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=1000000007;
const int inf=99999999;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

using namespace std;
map<string,int>M;
const int maxn=120010;
char str[maxn][50];
int main()
{
    int t=0;
    while(~scanf("%s",str[t])){
        M[str[t]]=1;
        t++;
    }
    for(int i=0;i<t;i++){
        int len=strlen(str[i]);
        for(int j=0;j<len;j++){
            char temp1[50]={'\0'};
            char temp2[50]={'\0'};
            strncpy(temp1,str[i],j);
            strncpy(temp2,str[i]+j,len-j);
            if(M[temp1]&&M[temp2]){
                printf("%s\n",str[i]);
                break;
            }
        }
    }
}


你可能感兴趣的:(UVA10391 Compound Words)