5 solutions
-
0
看到最小操作步数就想到了贪心 然后开始找怎么贪心 原理很好想 就看代码吧
#include<bits/stdc++.h> using namespace std; char a[10000]; char b[10000]; int main(){ cin>>a>>b; int num=0; int sum=0; int num1,num2; for(int i=0;i<strlen(a);i++){ if(a[i]!=b[i]){ num++; if(num==1){ num1=i; } else if(num==2){ num2=i; sum=num2-num1+sum; num=0; } } } cout<<sum; return 0; }
-
0
贪心没什么好说的
#include<bits/stdc++.h> using namespace std; int ans; int main() { std::ios::sync_with_stdio(false); string start; string finish; cin>>start>>finish; for(int i=0;i<start.length();i++) { if(start[i]!=finish[i]) { ans++; if(start[i]=='*')//i不一样就变化 start[i]='o'; else start[i]='*'; if(start[i+1]=='*')//i+1同时变化 start[i+1]='o'; else start[i+1]='*'; } } cout<<ans; return 0; }
-
0
#include<iostream> #include<cstring> using namespace std; const int N=1007; char a[N],b[N]; int ans; int main(){ cin>>a>>b; int n=strlen(a); for(int i=0;i<n-1;i++){ if(a[i]==b[i])continue; else if(a[i]=='*'){ ans++; if(a[i+1]=='*')a[i+1]='o'; else a[i+1]='*'; } else if(a[i]=='o'){ ans++; if(a[i+1]=='*')a[i+1]='o'; else a[i+1]='*'; } } cout<<ans; return 0; }
-
0
#include <bits/stdc++.h> using namespace std; #define accelerate ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define endl "\n"; #define mod 1000000007 int main(){ accelerate; string s; string ss; int ans=0; cin>>s>>ss; int i=0,j=0; while(i<s.size()-1){ if(s[i]!=ss[j]){ ans++; if(s[i+1]=='*') s[i+1]='o'; else s[i+1]='*'; } i++;j++; } cout<<ans; return 0; }
-
0
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<map> using namespace std; char arr1[1005]; char arr2[1005]; void op(int n)//函数操作两个字符串 { if (arr2[n] == '*') arr2[n] = 'o'; else arr2[n] = '*'; if (arr2[n+1] == '*') arr2[n+1] = 'o'; else arr2[n+1] = '*'; } int main(void) { cin.getline(arr1, 1000).getline(arr2, 1000); //数据输入 int len = strlen(arr1); int ans = 0; for (int i = 0; i < len; i++) { if (arr1[i] != arr2[i]) { ans++; op(i); } } cout << ans; //思想就是模拟翻硬币的过程 return 0; }
- 1
Information
- ID
- 1586
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 45
- Accepted
- 26
- Uploaded By