fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. #define M 1000
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. unsigned long long t;
  13. cin>>t;
  14. while(t--)
  15. {
  16. //declaration
  17. char strings[M][2];
  18. int en[26]={0},strt[26]={0};
  19. unsigned long long n,link=0;
  20. string inp;
  21. int flag[26]={0};
  22. int flag2[M]={0};
  23.  
  24.  
  25. cin>>n;
  26.  
  27. for(int i=1;i<=n;i++)
  28. {
  29. cin>>inp;
  30. strings[i-1][0]=inp[0];
  31. strings[i-1][1]=inp[inp.length()-1];
  32. strt[(int)inp[0]-(int)'a']++;
  33. en[(int)inp[inp.length()-1]-(int)'a']++;
  34.  
  35. }
  36.  
  37. for(int i=0;i<26;i++)
  38. link+=min(strt[i],en[i]);
  39.  
  40. //cout<<link<<endl;
  41. for(int i=0;i<n;i++)
  42. {
  43. if(strings[i][0]==strings[i][1] )
  44. {
  45. for(int j=i+1;j<n;j++)
  46. {
  47. if(strings[i][0]==strings[j][0] or strings[i][0]==strings[j][1] )
  48. {
  49. flag[(int)strings[j][0]-(int)'a']=1;
  50. flag[(int)strings[j][1]-(int)'a']=1;
  51. }
  52. }
  53. if(!flag[(int)strings[i][0]-(int)'a'])
  54. {
  55. link--;
  56. //cout<<strings[i][0]<<strings[i][1]<<endl;
  57. flag[(int)strings[i][0]-(int)'a']=1;
  58. }
  59.  
  60. }
  61.  
  62. else if(strings[i][0]!=strings[i][1] and !flag2[i])
  63. {
  64. for(int j=i+1;j<n;j++)
  65. {
  66. if(strings[i][0]==strings[j][1] and strings[j][0]==strings[i][1] and !flag2[j] )
  67. {
  68. link--;
  69. //cout<<strings[i][0]<<strings[i][1]<<endl;
  70. //cout<<strings[j][0]<<strings[j][1]<<endl;
  71. flag2[j]=1;
  72. flag[(int)strings[i][0]-(int)'a']=1;
  73. flag[(int)strings[i][1]-(int)'a']=1;
  74. break;
  75.  
  76. }
  77. }
  78.  
  79. }
  80. flag2[i]=1;
  81.  
  82. }
  83.  
  84. //cout<<link<<endl;
  85.  
  86. if(link>=n-1)
  87. cout<<"YES"<<endl;
  88. else
  89. cout<<"NO"<<endl;
  90. }
  91. return 0;
  92. }
  93.  
  94.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:19: fatal error: iostream: No such file or directory
compilation terminated.
stdout
Standard output is empty