Find and replace

This is a discussion on Find and replace within the C++ Programming forums, part of the General Programming Boards category; input 1 11 12 13 4 5 6 another input 11 12 13 9 the output should be 1 9 ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    6

    Find and replace

    input 1 11 12 13 4 5 6 another input 11 12 13 9 the output should be 1 9 4 5 6

    hey guys i am new to this forum i have a prob i want a c++ progrm to find an array from a txt file and replace with another. in this i hav 2 txt file one containing the relacing array another to be replaced. for example

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    That doesn't look much like replacing, more like a set difference.
    Anyway, what have you tried so far ?
    Kurt

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by ZuK View Post
    That doesn't look much like replacing, more like a set difference.
    Anyway, what have you tried so far ?
    Kurt
    Code:
    #include <cstring>
    #include <cstdio>
    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <map>
    #include <set>
    #include <algorithm>
    #define sz size()
    #define pb push_back
    #define _(x,a) memset(x,a,sizeof(x))
    #define LET(x,a) typeof(a) x(a)
    #define GFOR(i,a,b) for(LET(i,a);i!=(b);++i)
    #define FOR(i,a,b) for(int i=a;i<b;i++)
    #define REP(i,n) for(int i=0;i<n;i++)
    #define EACH(i,v) GFOR(i,(v).begin(),(v).end())
    #define LL long long
    #define GI ({int t;scanf("%d",&t);t;})
    #define GL ({LL t;scanf("%lld",&t);t;})
    #define GD ({double t;scanf("%lf",&t);t;})
    template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;} 
    template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;} 
    using namespace std;
    
    int main (int argc, char const* argv[]) {
        int l,count=0;
        int rep,v=0,pla=0;
        int  m,n;int nu[100];
        ifstream fin;
        fin.open("replace.txt");
        int a[100], b[100], c[100][100];int im=0;
        while(fin>>n) {
           int ora=0;
           nu[ora]=n;
           cout<<"before";
            pla++;ora++;
            REP(j,(n+1)) fin>>c[im][j];REP(j,(n+1))cout<<c[im][j]<<" ";cout<<endl;
        im++;}
        REP(i,pla) cout<<"strlen"<<endl<<nu[i]<<endl;
        REP(i,pla)
       { cout<<"done";
        {REP(j,(n+1))cout<<c[i][j]<<" ";cout<<endl;
    }}
        REP(i,pla) cout<<"strlen"<<endl<<nu[i]<<endl;
        cout<<pla; cout<<"done";
        cout<<endl<<endl<<endl<<endl;
        ifstream fin1;
        fin1.open("file.txt");
            while(fin1>>m) 
             REP(i,m) fin1>>a[i];
             REP(i,m) cout<<a[i];
             cout<<endl<<endl<<endl<<endl;
            REP(io,pla)
            {nu[io]=nu[io];
            int g; g = ((m+1)-n);
            cout<<endl<<"g="<<g<<endl;
    }
     /*   REP(i,pla)
        { int nxt=-1;
        REP(k,g){nxt++;count=0;
        REP(j,m)
        if(c[i][j+nxt]==a[j+nxt]) count++;
        if (count=3)
        {REP(i,nxt) cout<<a[i]<<" ";
        cout<<a[m];
        REP(i,n) cout<<c[(nxt+m-1+i)];
        }
        }//kg
        REP(i,n) cout<<c[i];
                    }//ipla
                cout<<"1";
       */         
        int zx;
        cin>>zx;
        return 0;
    }// int main

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    6
    i know the code is so bad i really dont have any idea huw to solve pls help

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    6
    the inpit format are
    input 1: <array length> <array>
    input 2: <array length> <array to be replaced> <replacing array>
    eg input 1: 7 1 2 13 14 6 8 9
    input 2: 3 2 13 14 0
    output: 7 1 0 6 8 9

  6. #6
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    1. Get rid of ALL the macros and unnecessary cruft . They are completely useless here.
    2. Take the first input into a std::set<int>.
    3. Erase the individual numbers in the 2nd input from the original set.
    4. Display it and you're done.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by manasij7479 View Post
    1. Get rid of ALL the macros and unnecessary cruft . They are completely useless here.
    2. Take the first input into a std::set<int>.
    3. Erase the individual numbers in the 2nd input from the original set.
    4. Display it and you're done.
    thanks a lot manasij but it wil be so helpful if i get the code for it i am a beginner now and pls help me

  8. #8
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  9. #9
    Registered User
    Join Date
    May 2012
    Posts
    6
    thanks

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    Delete lines 9-20, then make it work again without adding those lines back.
    Being a beginner is even more reason that you shouldn't invent your own meta language using a bunch of ridiculous macros. To the contrary, you need to use the standard constructs repeatedly until they are well stuck in your brain, and your muscle memory.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find/Replace problem
    By TAZIN in forum Windows Programming
    Replies: 6
    Last Post: 08-16-2010, 07:07 PM
  2. please help!...find and replace
    By amy589 in forum C++ Programming
    Replies: 26
    Last Post: 10-13-2006, 06:42 PM
  3. Find and replace
    By Sam Granger in forum C++ Programming
    Replies: 24
    Last Post: 11-03-2005, 01:34 PM
  4. find and replace
    By highlands in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2004, 08:57 AM
  5. Find and replace
    By BobDole1 in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2003, 10:06 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21