mercredi 5 août 2015

cutting first string from second string and show remaining characters


I want to code a program in which we take two strings separated by space as an input from user. Then the first string will be cut from second one, if resultant again have first string then again cut it from that string until there is no first string in second string as a result. The output will be the remaining characters in separated line and at the end a number that shows the quantity of those characters.

#include<iostream>
using namespace std;


int main() {
    string ch1, ch2, ch3;
    cout << " Enter  two strings values...separated by space..." << endl;
    cin >> ch1 >> ch2;
    //cout<<aa<<" 2nd  "<<bb<<endl;
    // ch1[]={"ab"},ch2[]={"caabbefcdeab"},ch3[50];
    int a = 0, b = 0, c;
    string s, t, r;
    int check = true;

    for (int i = 0; ch2[i] != '\0'; i++)
    {
        int w = i;
        check = 1;
        b = 0;
        if (ch1[0] == ch2[i])
        {
            for (int p = 0; ch1[p] != '\0' && check == 1; p++)
            {
                if (ch1[p] == ch2[w])
                {
                    check = 1;
                    w = w + 1;
                }
            }
            if (check == 1)
            {
                for (int e = i; e<w; e++)
                {
                    ch2[e] = '\0';
                    ch2[e] = '~';
                }
                i = -1;
                for (int l = 0; ch2[l] != '\0'; l++)
                {
                    ch3[l] = '\0';
                    if (ch2[l] != '~')
                    {
                        // cout<<" ch2 "<<ch2[l]<<endl;
                        ch3[b] = ch2[l];

                        // cout<<" ch3 "<<b<<" contains.."<<ch3[b]<<endl;
                        b = b + 1;
                    }
                }
                for (int l = 0; ch2[l] != '\0'; l++)
                {
                    ch2[l] = '\0';
                    ch2[l] = ch3[l];
                }
            }
        }
    }
    for (int u = 0; ch2[u] != '\0'; u++)
    {
        cout << ch2[u] << endl;
        a = a + 1;
        //  cout<<" ch3 "<<u<<" contains "<<ch3[u]<<endl;
    }
    cout << a << endl;

    system("pause");
    return 0;
}

Sample input:

cde ccdedefcde

Sample output:

f
1

But my output is:

d
e
f
3



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire