Advertisement
steverobinson

problem 1[with errors]

Oct 25th, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. //I have some other small errors too.
  2. //find a way to get new line char
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7.  
  8. using namespace std;
  9. int top=-1;
  10. struct word
  11. {
  12.     string  word;
  13. }word[10000];
  14.  
  15. void push(string tmp_word)
  16. {
  17.     //if(top==-1)
  18.  
  19.         top++;
  20.         word[top].word=tmp_word;
  21.  
  22.  
  23. }
  24.  
  25. int search(string tmp_word)
  26. {
  27.     for(int i=0;i<=top;i++)
  28.     {
  29.         if(word[i].word==tmp_word)
  30.         {
  31.             return ((top-1)+1);
  32.             string temp=tmp_word;
  33.             for(int j=i;j<=top;j++)
  34.             {
  35.                 word[j]=word[j+1];
  36.             }
  37.             word[top].word=temp;
  38.         }
  39.  
  40.     }
  41.     return -1;
  42. }
  43.  
  44. int main()
  45. {
  46.     string temp;
  47.     int op_num,flag,comma_flag;
  48.     char end_char;
  49.     ofstream file("output.txt",ios::trunc);
  50.     cin>>temp;
  51.     while(temp!='0')
  52.     {
  53.          for(int i=0;temp[i]!='\0';i++)
  54.         {
  55.             if(temp[i]=="."||temp[i]==",")
  56.             {
  57.                 comma_flag=1;
  58.                 end_char=temp[i];
  59.                 break;
  60.             }
  61.         }
  62.  
  63.         for(int i=0;temp[i]!='\0';i++)
  64.         {
  65.             if(temp[i]=="'"||temp[i]=="-")
  66.             {
  67.                 string new1,new2;
  68.                 new1=temp.substr(0,i);
  69.                 int length=temp.length();
  70.                 if(comma_flag)
  71.                 {
  72.                     new2=temp.substr(i+1,length-(new1.length()));
  73.                 op_num=search(new1);
  74.                     if(op_num!=-1)
  75.                     {
  76.                         file<<op_num;
  77.                     }
  78.  
  79.                     else
  80.                         file<<new1<<temp[i];
  81.                 op_num=search(new2);
  82.                     if(op_num!=-1)
  83.                         file<<op_num;
  84.                     else
  85.                         file<<new1<<end_char<<" ";
  86.                 }
  87.                 else
  88.                 {
  89.                     new2=temp.substr(i+1,length-(new1.length()+1));
  90.                 op_num=search(new1);
  91.                     if(op_num!=-1)
  92.                         file<<op_num;
  93.                     else
  94.                         file<<new1<<temp[i];
  95.                 op_num=search(new2);
  96.                     if(op_num!=-1)
  97.                         file<<op_num;
  98.                     else
  99.                         file<<new1<<" ";
  100.                 }
  101.  
  102.             }
  103.             flag=1;
  104.         }
  105.         if(!flag)
  106.         {
  107.             if(comma_flag)
  108.             {
  109.                 op_num=search(temp);
  110.                 if(op_num!=1)
  111.                 {
  112.                     file<<op_num<<end_char<<" ";
  113.                 }
  114.             }
  115.             else
  116.             {
  117.                 op_num=search(temp);
  118.                 if(op_num!=1)
  119.                 {
  120.                     file<<op_num<<" ";
  121.                 }
  122.             }
  123.         }
  124.     }
  125.     file.close();
  126.     ifstream file("output.txt");
  127.     char op_ch;
  128.     op_ch=getchar(file);
  129.     while(op_ch!=EOF)
  130.     {
  131.         cout<<op_ch;
  132.         op_ch=getchar(file);
  133.     }
  134.     return 0;
  135.  
  136.  
  137.  
  138.  
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement