TOPIC

WA 100% mas passa em todos uDebug

Victor Hugo asked 2 years ago

Codigo:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
    string x,y,palavra="";
    int n,tamanho2,cont=0;
    cin>>n;
    for(int z=0;z<n;z++){
        cont=0;
        palavra="";
       cin>>x>>y;
       tamanho2=y.length();
       for(int i=(x.length()-tamanho2);i<x.length();i++){
               palavra+=x[i];
               cont++;
       }
       if(palavra==y){
           cout<<"encaixa"<<endl;
       }else{
           cout<<"nao encaixa"<<endl;
       }
    }
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 years ago

    line #14: x.length() can be less than tamanho2, so you can start the cicle with negative value.