Test instructions
Given a dictionary, ask to find all the compound words;
Ideas:
Use map to save the words, and then open the words to see if they are the words that appear;
AC Code:
#include <bits/stdc++.h>#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#definefor (i,j,n) for (int i=j;i<=n;i++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong Longll;template<classT>voidRead (t&num) { CharCH;BOOLf=false; for(Ch=getchar (); ch<'0'|| Ch>'9'; f= ch=='-', ch=GetChar ()); for(num=0; ch>='0'&&ch<='9'; num=num*Ten+ch-'0', ch=GetChar ()); F&& (num=-num);}intstk[ -], Tp;template<classT> Inlinevoidprint (T p) {if(!p) {Puts ("0");return; } while(p) stk[++ TP] = p%Ten, p/=Ten; while(TP) Putchar (stk[tp--] +'0'); Putchar ('\ n');}ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=1e9;Const intn=12e4+Ten;Const intmaxn=1e3+Ten;Const Doubleeps=1e-Ten;intN;stringS[n];map<string,int>MP;intMain () {intCNT =0; while(cin>>s[++CNT]) {mp[s[cnt]]=1; } stringb; For (I,1, CNT) { intlen=s[i].size (); For (J,0, len-1) {a=S[I].SUBSTR (0, j+1); b=s[i].substr (j+1); if(mp[a]&&Mp[b]) {cout<<s[i]<<"\ n"; Break; } } } return 0;}
UVA-10391 (String retrieval)