2020 cattle off winter training camp 5 A basic algorithm template

https://ac.nowcoder.com/acm/contest/3006/A

Title Description

Beef, beef cattle and cola can make up a team to participate in ACM Series tournament, they played a team called ~ elegant "beef clan."

Taurus team in the absence of competition, will put all kinds of board cabinet password, to prevent lost. This whole team is headed by a password. Beef cattle and which can have two keys, each of which has a merely constituted by the capital letter string. Coke holds the cow decryption method. One day, you use a bottle of Coke Cola bribery cattle, it has been decrypted way:

Bovine Coke will attempt to use one key into another by as few steps as following:

  • Wherein any of the letter is replaced with another
  • To delete the last letter
  • Add a letter in the tail

Digital conversion step is to get the final password.

One day, you and your team dinner with them, you fill them with cola poured from the mouth of beef and cattle can set out two keys. You want to take them to wake up and get a copy of the template before putting them back. You can quickly calculate your password?

Thinking

Because each time only in the tail deletions, modifications intermediate only, so for the same length of the two strings if the bit modification directly to different first length is set to the same length, then the bit modification

/*************************************************************************
    > File Name: A.cpp
    > Author: amoscykl
    > Mail: [email protected]
    > Created Time: 2020年02月13日 星期四 13时26分17秒
 ************************************************************************/
 
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char a[N], b[N];
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    scanf("%s %s", a, b);
    int lena = strlen(a);
    int lenb = strlen(b);
    int mn = min(lena, lenb);
    int res = 0;
    for (int i = 0; i < mn; i++){
        if (a[i] != b[i])++res;
    }
    res += abs(lena - lenb);
    printf("%d\n", res);
    return 0;
}

 

Published 204 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43701790/article/details/104308210