Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I have some other small errors too.
- //find a way to get new line char
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int top=-1;
- struct word
- {
- string word;
- }word[10000];
- void push(string tmp_word)
- {
- //if(top==-1)
- top++;
- word[top].word=tmp_word;
- }
- int search(string tmp_word)
- {
- for(int i=0;i<=top;i++)
- {
- if(word[i].word==tmp_word)
- {
- return ((top-1)+1);
- string temp=tmp_word;
- for(int j=i;j<=top;j++)
- {
- word[j]=word[j+1];
- }
- word[top].word=temp;
- }
- }
- return -1;
- }
- int main()
- {
- string temp;
- int op_num,flag,comma_flag;
- char end_char;
- ofstream file("output.txt",ios::trunc);
- cin>>temp;
- while(temp!='0')
- {
- for(int i=0;temp[i]!='\0';i++)
- {
- if(temp[i]=="."||temp[i]==",")
- {
- comma_flag=1;
- end_char=temp[i];
- break;
- }
- }
- for(int i=0;temp[i]!='\0';i++)
- {
- if(temp[i]=="'"||temp[i]=="-")
- {
- string new1,new2;
- new1=temp.substr(0,i);
- int length=temp.length();
- if(comma_flag)
- {
- new2=temp.substr(i+1,length-(new1.length()));
- op_num=search(new1);
- if(op_num!=-1)
- {
- file<<op_num;
- }
- else
- file<<new1<<temp[i];
- op_num=search(new2);
- if(op_num!=-1)
- file<<op_num;
- else
- file<<new1<<end_char<<" ";
- }
- else
- {
- new2=temp.substr(i+1,length-(new1.length()+1));
- op_num=search(new1);
- if(op_num!=-1)
- file<<op_num;
- else
- file<<new1<<temp[i];
- op_num=search(new2);
- if(op_num!=-1)
- file<<op_num;
- else
- file<<new1<<" ";
- }
- }
- flag=1;
- }
- if(!flag)
- {
- if(comma_flag)
- {
- op_num=search(temp);
- if(op_num!=1)
- {
- file<<op_num<<end_char<<" ";
- }
- }
- else
- {
- op_num=search(temp);
- if(op_num!=1)
- {
- file<<op_num<<" ";
- }
- }
- }
- }
- file.close();
- ifstream file("output.txt");
- char op_ch;
- op_ch=getchar(file);
- while(op_ch!=EOF)
- {
- cout<<op_ch;
- op_ch=getchar(file);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement