HDU 6208 The Dominator of Strings(stl)

超、凢脫俗 2022-06-08 07:57 217阅读 0赞

The Dominator of Strings

Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2439 Accepted Submission(s): 879

Problem Description

Here you have a set of strings. A dominator is a string of the set dominating all strings else. The string S is dominated by T if S is a substring of T.

Input

The input contains several test cases and the first line provides the total number of cases.
For each test case, the first line contains an integer N indicating the size of the set.
Each of the following N lines describes a string of the set in lowercase.
The total length of strings in each case has the limit of 100000.
The limit is 30MB for the input file.

Output

For each test case, output a dominator if exist, or No if not.

Sample Input

  1. 3
  2. 10
  3. you
  4. better
  5. worse
  6. richer
  7. poorer
  8. sickness
  9. health
  10. death
  11. faithfulness
  12. youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness
  13. 5
  14. abc
  15. cde
  16. abcde
  17. abcde
  18. bcde
  19. 3
  20. aaaaa
  21. aaaab
  22. aaaac

Sample Output

  1. youbemyweddedwifebetterworsericherpoorersicknesshealthtilldeathdouspartandpledgeyoumyfaithfulness
  2. abcde
  3. No

Source

2017 ACM/ICPC Asia Regional Qingdao Online

Recommend

liuyiding | We have carefully selected several similar problems for you: 6216 6215 6214 6213 6212

题解:

很水的一题,暴力就可以解决,直接取最长的作为模板串,如果和他等长的串和他不相同就不可以,然后其他的串要在那个串里面找得到。。。

比赛的时候我tm也是醉了,莫名其妙wa了好几遍,最后也没发现错,后来比完赛才知道错在了取消了cin和cout的同步以后用printf就会出错了。。。我把printf改成cout就ac了,我%@#¥@#¥@#¥@,以后不能随便用取消同步了

代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<stdio.h>
  4. #include<math.h>
  5. #include<string>
  6. #include<stdio.h>
  7. #include<queue>
  8. #include<stack>
  9. #include<map>
  10. #include<vector>
  11. #include<deque>
  12. #include<algorithm>
  13. #define ll long long
  14. #define INF 100861111
  15. #define M (t[k].l+t[k].r)/2
  16. #define lson k*2
  17. #define rson k*2+1
  18. using namespace std;
  19. struct node
  20. {
  21. string s;
  22. };
  23. node p[100005];
  24. string t;
  25. int main()
  26. {
  27. std::ios::sync_with_stdio(false);
  28. int test,i,j,n,num,maxx,tag;
  29. scanf("%d",&test);
  30. while(test--)
  31. {
  32. scanf("%d",&n);
  33. maxx=0;
  34. for(i=0;i<n;i++)
  35. {
  36. cin>>p[i].s;
  37. if(p[i].s.size()>maxx)
  38. {
  39. maxx=p[i].s.size();
  40. t=p[i].s;
  41. }
  42. }
  43. tag=1;
  44. for(i=0;i<n;i++)
  45. {
  46. if(p[i].s.size()==maxx)
  47. {
  48. if(p[i].s!=t)
  49. {
  50. tag=0;
  51. break;
  52. }
  53. }
  54. else
  55. {
  56. if(t.find(p[i].s)==string::npos)
  57. {
  58. tag=0;
  59. break;
  60. }
  61. }
  62. }
  63. if(tag)
  64. cout<<t<<endl;
  65. else
  66. cout<<"No"<<endl;
  67. }
  68. return 0;
  69. }

发表评论

表情:
评论列表 (有 0 条评论,217人围观)

还没有评论,来说两句吧...

相关阅读