1 solutions
-
1
#include<bits/stdc++.h> using namespace std; bool check(string s1,string s2) { if(s1.size()<s2.size()) swap(s1,s2); int n=s1.size(),m=s2.size(); if(n==m) { int cnt=0; for(int i=0;i<n;i++) { if(s1[i]!=s2[i]) cnt++; } if(cnt>1) return false; return true; } else { int i=0,j=0; int cnt=0; if(n>m+1) return false;//至少需要添加两个 // if(s1=="applee") cout<<s1<<" "<<s2<<endl; while(i<n&&j<m) { if(s1[i]!=s2[j]) //说明需要s2添加 { cnt++; if(cnt>1) return false; //至少有两个不同 i++; } else { i++,j++; } } return true; } } int main() { int t; cin>>t; while(t--) { string s1,s2; cin>>s1>>s2; if(check(s1,s2)) cout<<"similar"<<endl; else cout<<"not similar"<<endl; } return 0; }
Information
- ID
- 2167
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- # Submissions
- 12
- Accepted
- 4
- Uploaded By