Skip to content

Latest commit

 

History

History
48 lines (42 loc) · 972 Bytes

0080.翻转.md

File metadata and controls

48 lines (42 loc) · 972 Bytes

80. 翻转

题目链接

C

C++

//思路,满足三个性质: 1:不可逆性,101在变成111的时候,111是不可能恢复成101的 2:不可能对连续的两个字符同时进行操作 3:字符串想通过位置的字符不同时必须要改变,相同的字符必须不改变,即不做任何操作 #include<bits/stdc++.h> using namespace std; const int N=1e6+10; char s[N],t[N]; int main() { int T; cin>>T; while(T--) { scanf("%s%s",t,s); int n=strlen(s); int res=0; for(int i=0;i<n;i++) { if(s[i]!=t[i]) { if(!i||i==n-1||s[i]==s[i-1]||s[i]==s[i+1]) { res=-1; break; } res++; s[i]=t[i]; } } printf("%d\n",res); } return 0; }

Java

Python

JS

Go