题意:
给定字符串 $S$,$T$,请求出两者第一个不同的字符的位置。
Solution:
由于字符串的长度很短,所以我们可以枚举较短的字符串每个字符,直到找到不同的字符为止,并输出这个字符的位置。
如果较短的字符串中并未找到不同的字符,那么这个字符一定在较长的字符串的末尾。
Code:
#include<iostream>
#include<algorithm>
#include<string>
int main() {
std::ios::sync_with_stdio(false);
std::string s, t;
std::cin >> s >> t;
for (int i = 1; i <= std::min(s.length(), t.length()); i++)
if (s[i - 1] != t[i - 1]) std::cout << i, exit(0);
std::cout << std::max(s.length(), t.length());
return 0;
}