DontCallMeNuttoPleas

WordChain

Mar 22nd, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool check(char a[],char b[]){
  5.     int n=strlen(a);
  6.     int cnt=0;
  7.     for(int i=0;i<n;i++){
  8.         if(a[i]!=b[i]) cnt++;
  9.         if(cnt>2) return true;
  10.     }
  11.     return false;
  12. }
  13.  
  14. int main(){
  15.     int n,m;
  16.     scanf("%d%d",&n,&m);
  17.     char a[n+2],b[n+2];
  18.     bool chk=0;
  19.     for(int i=0;i<m;i++){
  20.         if(i!=0&&!chk) strcpy(b,a);
  21.         scanf("%s",a);
  22.         if(i==0||chk) continue;
  23.         if(check(a,b)){
  24.             chk=1;
  25.         }
  26.     }
  27.     if(chk==1) cout << b;
  28.     else
  29.     cout << a;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment