AtCoder Beginner Contest 386
C - Operate 1
思路
简单的条件判断题
代码
#include <bits/stdc++.h>
typedef std::pair<int, int> pii;
#define INF 0x3f3f3f3f
#define MOD 998244353
using i64 = long long;
const int N = 1e5+5;
void solve(){
int k;
std::string s, t;
std::cin >> k >> s >> t;
int n = s.size(), m = t.size(), ans = 0;
if (n == m){
for (int i = 0; i < n; i++){
if (s[i] != t[i]){
k -= 1;
if (k < 0) {
break;
}
}
}
if (k < 0) ans = 0;
else ans = 1;
}else if (n == m + 1){
int index = 0;
for (int i = 0; i < n; i++){
if (s[i] == t[index]){
index++;
}
}
if (index == m){
ans = 1;
}else{
ans = 0;
}
}else if (m == n + 1){
int index = 0;
for (int i = 0; i < m; i++){
if (t[i] == s[index]) index++;
}
if (index == n){
ans = 1;
}else{
ans = 0;
}
}else{
ans = 0;
}
std::cout << (ans == 0 ? "No\n" : "Yes\n");
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(2);
int t = 1, i;
for (i = 0; i < t; i++){
solve();
}
return 0;
}
标签:std,AtCoder,index,int,else,++,补题,386,ans
From: https://www.cnblogs.com/califeee/p/18644144