Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ////////////////////////////////////////
- /// dealing with data
- struct data
- {
- string owner_name,
- address,
- mob;
- float value;
- };
- ////////////////////////////////////////////////
- // structure of node
- struct node
- {
- data d;
- string u_id;
- int nodeNo;
- node* parent;
- string password;
- vector<node*> child;
- }*ptr;
- ////////////////////////////////////////////////
- // Global Variables
- int nodeNum=0;
- int new_node=1;
- vector<node*> heads;
- map<string,string> pass;
- map<string,node*> own_map;
- ///////////////////////////////
- string encrypt_string(string s) //Encryption of string
- {
- for(int i=0;s[i]!='\0';i++)
- s[i]+=1*(i+1);
- return s;
- }
- //Decryption of string
- string decrypt_string(string s)
- {
- for(int i=0;s[i]!='\0';i++)
- s[i]-=1*(i+1);
- return s;
- }
- void encrypt(data &x) //Encrypt
- {
- x.owner_name=encrypt_string(x.owner_name);
- x.address=encrypt_string(x.address);
- x.mob=encrypt_string(x.mob);
- x.value+=1;
- }
- //Decrypt
- void decrypt(data &x)
- {
- x.owner_name=decrypt_string(x.owner_name);
- x.address=decrypt_string(x.address);
- x.mob=decrypt_string(x.mob);
- x.value-=1;
- }
- void get_data(data &x)
- {
- cin>>x.owner_name>>x.address>>x.mob>>x.value;
- encrypt(x);
- }
- void put_data(data &x)
- {
- decrypt(x);
- cout<<x.owner_name<<x.address<<x.mob<<x.value;
- }
- ////////////////////////////////////////////////////////////////////////////
- node *create_node() // Node Creation
- {
- node* p=new node;
- cin>>p->u_id;
- cin>>p->password;
- pass.insert(make_pair(p->u_id,p->password));
- get_data(p->d);
- if(new_node==1)
- {
- nodeNum++;
- p->nodeNo=nodeNum;
- }
- else
- {
- p->nodeNo=nodeNum;
- }
- p->parent=NULL;
- new_node=1;
- own_map.insert(make_pair(p->u_id,p));
- return p;
- }
- int flag=0;
- node* search_node(node* t,string s) //Search for a parent node after which new node is to be inserted
- {
- if(!flag)
- {
- if(t->u_id==s)
- {
- flag=1;
- return t;
- }
- for(int i=0;i<t->child.size();i++)
- {
- search_node(t->child[i],s);
- }
- return t;
- }
- return t;
- }
- void add_node(node* start) //Add node to any set
- {
- string s_id;
- cin>>s_id;
- new_node=0;
- node* temp=search_node(start,s_id);
- node* p=create_node();
- p->parent=temp;
- temp->child.push_back(p);
- }
- bool verify_owner(string s_id,string pswd) // unique id->pswd verification
- {
- if(pass[s_id]==pswd)
- return true;
- return false;
- }
- void print_node(node* p)
- {
- cout<<p->u_id<<p->nodeNo;
- put_data(p->d);
- }
- int main()
- {
- string s_id,pswd;
- int c;
- cin>>c;
- switch(c)
- {
- case 1:
- ptr=create_node(); //Create more than one sets of nodes
- heads.push_back(ptr);
- break;
- case 2: //Add node in a particular set after a particular node
- int which_set; //specified by its unique id
- cin>>which_set;
- add_node(heads[which_set-1]);
- break;
- case 3:
- //owner verification step
- cin>>s_id>>pswd;
- ptr=NULL;
- if(verify_owner(s_id,pswd))
- {
- ptr=own_map[s_id];
- print_node(ptr);
- }
- break;
- default :
- break;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment