fork download
  1. #include <iostream>
  2. #include<string>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. struct word{
  7. char *str;
  8. int index;
  9. };
  10. struct DupArray{
  11. struct word* array;
  12. int size;
  13. };
  14. struct DupArray* CreateDupArray(char **str,int size)
  15. {
  16. struct DupArray node1;
  17. struct DupArray* node=&node1;
  18. node->array=new word[size+1];
  19. node->size=size;
  20. int i,j;
  21. for(i=0;i<size;i++)
  22. {
  23. int l=sizeof(str[i]);
  24. node->array[i].str=new char[l+1];
  25. node->array[i].str=str[i];
  26. node->array[i].index=i;
  27. }
  28. return node;
  29.  
  30. }
  31.  
  32. bool comp(const void *a,const void *b)
  33. {
  34. return (*(char *)a)<(*(char*)b);
  35. }
  36.  
  37. /*bool compStruct(const void *a,const void *b)
  38. {
  39.   struct word * a1=(struct word *)a;
  40.   struct word * b1=(struct word *)b;
  41.   string str1=a1->str;
  42.   string str2=b1->str;
  43.   return str1.compare(str2)>0;
  44. }*/
  45. void printCountAllAnagrams(char **array,int size)
  46. {
  47. cout<<"inside \n";
  48. struct DupArray *pointer=CreateDupArray(array,size);
  49. cout<<"inside **\n";
  50. int i,j;
  51. for(i=0;i<size;i++)
  52. {
  53.  
  54. std::sort(pointer->array[i].str,pointer->array[i].str+sizeof(pointer->array[i].str));
  55. }
  56. // std::sort(pointer->array,pointer->array+size,compStruct);
  57. /*for(i=0;i<size;i++)
  58.   {
  59.   cout<<""<<array[pointer->array[i].index]<<" ";
  60.   }*/
  61. int *CountArray=new int[size+1];
  62. for(i=0;i<size;i++)CountArray[i]=0;
  63. cout<<"kasjdhadh"<<"\n";
  64. /* for(i=0;i<size-1;i++)
  65.   {
  66.   for(j=i+1;j<size;j++)
  67.   {
  68.   if(CountArray[j]==-1)continue;
  69.   // if((pointer->array[i].str).compare(pointer->array[i].str)==0)
  70.   if((pointer->array[i].str)==(pointer->array[j].str))
  71.   {
  72.   CountArray[i]++;
  73.   CountArray[j]=-1;
  74.  
  75.   }
  76.   }
  77.   }
  78.   std::sort(CountArray,CountArray+size);*/
  79. for(i=0;i<size;i++)
  80. {
  81. if(CountArray[i]==-1)continue;
  82. else
  83. {
  84. cout<<CountArray[i]<<" ";
  85. }
  86. }
  87. cout<<"\n";
  88. return;
  89. }
  90.  
  91. int main() {
  92. int t,i,j,k,n;
  93. // cout<<"sds\n";
  94. cin>>t;
  95. // cout<<"t ="<<t<<"\n";
  96. for(i=0;i<t;i++)
  97. {
  98. cin>>n;
  99. cout<<"\n n="<<n<<"\n";
  100. char **array=new char*[n+1];
  101. for(j=0;j<n+1;j++)array[j]=new char[1000000];
  102. string *str=new string[n+1];
  103. cin.ignore();
  104. string str1;
  105. // for(j=0;j<n;j++)
  106. // {
  107. //cin>>array[j];
  108. //cin>>str1;
  109. getline(cin,str1,'\n');
  110. str1+=" ";
  111. k=0;int f=0;
  112. // cout<<"###***"<<str1<<"***\n";
  113. for(j=0;j<str1.size();j++)
  114. {
  115. if(str1[j]==' '){array[k][j]='\0';k++;f=0;continue;}
  116. else array[k][f++]=str1[j];
  117. }
  118. // cout<<"\n^%$^&***\n";
  119. for(k=0;k<n;k++)cout<<""<<array[k]<<" ";
  120. // cout<<"\n^%$^&***";
  121. // cin.ignore();
  122. //for(k=0;k<str1.size();k++)array[j][k]=str1[k];
  123. // cout<<"***"<<str1<<"***\n";
  124. //array[j]=str1.c_str();
  125. //cout<<"***"<<str[j]<<"***\n";
  126. // cout<<"***"<<array[j]<<"***\n";
  127. // }
  128. // cin.ignore();
  129. // cout<<"\n adakdh\n";
  130. //printCountAllAnagrams(array,n);
  131. }
  132.  
  133. //code
  134. return 0;
  135. }
Success #stdin #stdout 0s 25040KB
stdin
2
5
act cat tac god dog
3
act cat tac
stdout
 n=5
act cat tac god dog 
 n=3
act cat tac