Guest User

Untitled

a guest
Aug 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. ////////////////////////////////////////
  6. /// dealing with data
  7.  
  8. struct data
  9. {
  10. string owner_name,
  11. address,
  12. mob;
  13.  
  14. float value;
  15. };
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. ////////////////////////////////////////////////
  23. // structure of node
  24. struct node
  25. {
  26. data d;
  27. string u_id;
  28. int nodeNo;
  29. node* parent;
  30. string password;
  31.  
  32. vector<node*> child;
  33. }*ptr;
  34.  
  35.  
  36. ////////////////////////////////////////////////
  37. // Global Variables
  38. int nodeNum=0;
  39. int new_node=1;
  40. vector<node*> heads;
  41. map<string,string> pass;
  42. map<string,node*> own_map;
  43.  
  44.  
  45.  
  46.  
  47. ///////////////////////////////
  48. string encrypt_string(string s) //Encryption of string
  49. {
  50. for(int i=0;s[i]!='\0';i++)
  51. s[i]+=1*(i+1);
  52.  
  53. return s;
  54. }
  55. //Decryption of string
  56. string decrypt_string(string s)
  57. {
  58. for(int i=0;s[i]!='\0';i++)
  59. s[i]-=1*(i+1);
  60.  
  61. return s;
  62. }
  63.  
  64. void encrypt(data &x) //Encrypt
  65. {
  66. x.owner_name=encrypt_string(x.owner_name);
  67. x.address=encrypt_string(x.address);
  68. x.mob=encrypt_string(x.mob);
  69. x.value+=1;
  70. }
  71.  
  72. //Decrypt
  73. void decrypt(data &x)
  74. {
  75. x.owner_name=decrypt_string(x.owner_name);
  76. x.address=decrypt_string(x.address);
  77. x.mob=decrypt_string(x.mob);
  78. x.value-=1;
  79. }
  80.  
  81.  
  82. void get_data(data &x)
  83. {
  84. cin>>x.owner_name>>x.address>>x.mob>>x.value;
  85. encrypt(x);
  86. }
  87.  
  88. void put_data(data &x)
  89. {
  90. decrypt(x);
  91. cout<<x.owner_name<<x.address<<x.mob<<x.value;
  92.  
  93. }
  94. ////////////////////////////////////////////////////////////////////////////
  95.  
  96.  
  97.  
  98.  
  99.  
  100. node *create_node() // Node Creation
  101. {
  102. node* p=new node;
  103. cin>>p->u_id;
  104. cin>>p->password;
  105. pass.insert(make_pair(p->u_id,p->password));
  106. get_data(p->d);
  107. if(new_node==1)
  108. {
  109. nodeNum++;
  110. p->nodeNo=nodeNum;
  111. }
  112. else
  113. {
  114. p->nodeNo=nodeNum;
  115. }
  116. p->parent=NULL;
  117. new_node=1;
  118.  
  119. own_map.insert(make_pair(p->u_id,p));
  120. return p;
  121. }
  122.  
  123. int flag=0;
  124. node* search_node(node* t,string s) //Search for a parent node after which new node is to be inserted
  125. {
  126. if(!flag)
  127. {
  128. if(t->u_id==s)
  129. {
  130. flag=1;
  131. return t;
  132. }
  133.  
  134. for(int i=0;i<t->child.size();i++)
  135. {
  136. search_node(t->child[i],s);
  137. }
  138.  
  139. return t;
  140. }
  141. return t;
  142. }
  143.  
  144.  
  145. void add_node(node* start) //Add node to any set
  146. {
  147. string s_id;
  148. cin>>s_id;
  149. new_node=0;
  150. node* temp=search_node(start,s_id);
  151.  
  152. node* p=create_node();
  153. p->parent=temp;
  154. temp->child.push_back(p);
  155.  
  156. }
  157.  
  158.  
  159. bool verify_owner(string s_id,string pswd) // unique id->pswd verification
  160. {
  161.  
  162. if(pass[s_id]==pswd)
  163. return true;
  164.  
  165. return false;
  166. }
  167.  
  168. void print_node(node* p)
  169. {
  170. cout<<p->u_id<<p->nodeNo;
  171. put_data(p->d);
  172. }
  173.  
  174.  
  175. int main()
  176. {
  177. string s_id,pswd;
  178. int c;
  179. cin>>c;
  180. switch(c)
  181. {
  182. case 1:
  183. ptr=create_node(); //Create more than one sets of nodes
  184. heads.push_back(ptr);
  185. break;
  186. case 2: //Add node in a particular set after a particular node
  187. int which_set; //specified by its unique id
  188. cin>>which_set;
  189. add_node(heads[which_set-1]);
  190. break;
  191. case 3:
  192. //owner verification step
  193. cin>>s_id>>pswd;
  194. ptr=NULL;
  195. if(verify_owner(s_id,pswd))
  196. {
  197. ptr=own_map[s_id];
  198. print_node(ptr);
  199. }
  200. break;
  201. default :
  202. break;
  203. }
  204.  
  205.  
  206.  
  207. return 0;
  208. }
Add Comment
Please, Sign In to add comment