3 Star 60 Fork 5

programmercarl / kamacoder-solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0080.翻转.md 972 Bytes
一键复制 编辑 原始数据 按行查看 历史
huanheart 提交于 2024-02-19 15:32 . Update 0080.翻转.md

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

1
https://gitee.com/programmercarl/kamacoder-solutions.git
git@gitee.com:programmercarl/kamacoder-solutions.git
programmercarl
kamacoder-solutions
kamacoder-solutions
main

搜索帮助