mercredi 28 mars 2018

how does stringstream work with objects?

#include <iostream>

using namespace std;

int main()
{
    int nc,cy,n1,n2,r;
    cy=0;
    string in;
    cin>>in;
    cin>>nc;
    while(cy<nc){
        int l1,l2;
        cin>>l1>>l2;
        if(l1<l2){
                n1=l1;
                n2=l2;
        }
        if(l1>l2) {
                n1=l2;
                n2=l1;
        }
        if(l1==l2){
            cout<<"Yes"<<endl;
            continue ;
        }
        for(;n1<n2;n1++){
            if(in[n1]==in[n2])
                r=1;
            else{
                cout<<"No"<<endl;
                continue ;
            }

        }
        if(r==1)
            cout<<"Yes"<<endl;

        cy++;

    }

    return 0;
}

The user will put the first index and the second of the string if all are zeroes or all are ones between the indexes it will output yes else it will output no but some cases don't work properly.

Aucun commentaire:

Enregistrer un commentaire