fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int total;
  4. struct node{
  5. int cnt_trees;
  6. node *next[128];
  7. node(){
  8. cnt_trees=0;
  9. for(int i=0;i<128;i++) next[i]=NULL;
  10. }
  11. }*root;
  12.  
  13. void insert_into_Trie(char* str){
  14. node *cur=root;
  15. for(int i=0;str[i];i++){
  16. int id=str[i];
  17. if(cur->next[id]==NULL)
  18. cur->next[id]=new node();
  19. cur=cur->next[id];
  20. }
  21. cur->cnt_trees++;
  22. }
  23.  
  24. void printTree(node *cur,vector<char>name){
  25. if(cur->cnt_trees){
  26. for(auto x:name){
  27. printf("%c",x);
  28. }
  29. cout<<' '<<setprecision(4)<<fixed<<(100.0*(double)(cur->cnt_trees))/(double)(total)<<endl;
  30. }
  31.  
  32.  
  33. for(int i=0;i<128;i++){
  34. if(cur->next[i]!=NULL){
  35. name.push_back(i);
  36. printTree(cur->next[i],name);
  37. name.pop_back();
  38. }
  39. }
  40. name.pop_back();
  41. }
  42.  
  43. void del(node* cur)
  44. {
  45. for(int i= 0;i<128;i++)
  46. if (cur->next[i])
  47. del(cur->next[i]);
  48.  
  49. delete(cur);
  50. }
  51.  
  52. int main()
  53. {
  54. int n,q,tc;
  55. char str[21];
  56. scanf("%d\n\n",&n);
  57. tc=n;
  58. while(n--){
  59. root=new node();
  60. total=0;
  61. while(gets(str)){
  62. if(strlen(str)==0)break;
  63. insert_into_Trie(str);
  64. total++;
  65. }
  66. vector<char>name;
  67. printTree(root,name);
  68. if(--tc)printf("\n");
  69. del(root);
  70. }
  71. return 0;
  72. }
  73.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:61:21: error: ‘gets’ was not declared in this scope
       while(gets(str)){
                     ^
stdout
Standard output is empty