lanqiao/是否有字符串.c
2024-11-24 15:33:02 +08:00

54 lines
1.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 【问题描述】
// 一个字符串包含LANQIAO是指在字符串中能取出几个字符将他们按照在原串中的位置顺序摆成一排后字符串为 LANQIAO 。即字符串包含 LANQIAO 是指 LANQIAO 是这个串的子序列。
// 例如LLLLLANHAHAHAQLANIIIIALANO 中包含 LANQIAO 。
// 又如OAIQNAL 中不包含 LANQIAO 。
// 给点一个字符串,判断字符串中是否包含 LANQIAO 。
// 【输入格式】
// 输入一行包含一个字符串。
// 【输出格式】
// 如果包含 LANQIAO ,输出一个英文单词 YES ,否则输出一个英文单词 NO 。
// 【样例输入】
// LLLLLANHAHAHAQLANIIIIALANO
// 【样例输出】
// YES
// 【样例输入】
// OAIQNAL
// 【样例输出】
// NO
// 【评测用例规模与约定】
// 对于所有评测用例,输入的字符串非空串,由大写字母组成,长度不超过 1000 。
#include <stdio.h>
#include <string.h>
int main() {
char s[1001];
fgets(s, 1001, stdin);
// 去掉换行符
size_t len = strlen(s);
if (len > 0 && s[len-1] == '\n') {
s[len-1] = '\0';
}
char t[] = "LANQIAO";
int j = 0;
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == t[j]) {
j++;
if (j == 7) {
break;
}
}
}
if (j == 7) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}