fork download
  1. #include <cstdio>
  2. #include <map>
  3. #include <set>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <cstdlib>
  7. #include <sstream>
  8. #include <cmath>
  9. #include <map>
  10. #include <vector>
  11. #include <queue>
  12. using namespace std;
  13. #define FOR(i, x) for (int i = 0; i < x; i++)
  14. #define FORI(i,a, x) for (int i = a; i < x; i++)
  15. #define ALL(x) (x).begin(), (x).end()
  16. #define FORE(i, x) for (__typeof__((x).begin()) i = (x).begin(); i != (x).end(); i++)
  17. #define SZ(x) ((int) (x).size())
  18. #define EPS 1E-9
  19. #define MAX 30
  20. #define GETNUM(n) { \
  21. int sgn=1; \
  22. n=0; \
  23. if(*start=='-') { sgn=-1; start++; } \
  24. while (*start>='0' && *start<='9') { \
  25. n*=10; n+=*start-'0'; \
  26. start++; \
  27. } \
  28. n *= sgn; \
  29. }
  30. #define GETCHAR(c) { \
  31. c=*start; \
  32. start++; \
  33. }
  34. int main()
  35. {
  36. #ifndef ONLINE_JUDGE
  37. freopen("in/2943.in","r",stdin);
  38. freopen("out/2943.out","w",stdout);
  39. #endif
  40. int N;
  41. map<string,string> dict;
  42. string str, w;
  43. getline(cin,str);
  44. sscanf(str.c_str(),"%d",&N);
  45. FOR(i,N)
  46. {
  47. getline(cin,w);
  48. str=w;
  49. if(SZ(str)>2) sort(str.begin()+1,str.end()-1);
  50. dict.insert(pair<string,string>(str,w));
  51. }
  52. while(getline(cin,str))
  53. {
  54. bool first = true;
  55. istringstream sstr(str);
  56. while(sstr >> str)
  57. {
  58. if(SZ(str)>2) sort(str.begin()+1,str.end()-1);
  59. if(!first) cout << " ";
  60. cout << dict[str];
  61. first = false;
  62. }
  63. cout << endl;
  64. }
  65. return 0;
  66. }
Success #stdin #stdout 0s 3444KB
stdin
26
and
beauty
but
changing
face
false
glad
grace
how
in
love
loved
man
many
moments
of
one
or
pilgrim
sorrows
soul
the
true
with
you
your
how mnay loevd yuor moemtns of gald gcrae
and lveod yuor baetuy wtih lvoe flase or true
but one man leovd the pligirm suol in you
and levod the sorwors of yuor chnganig fcae
stdout
how many loved your moments of glad grace
and loved your beauty with love false or true
but one man loved the pilgrim soul in you
and loved the sorrows of your changing face