输入一串字符,字符个数不超过100,且以.结束,判断它们是否构成回文。
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1026
输入一串字符,字符个数不超过100,且以.结束,判断它们是否构成回文。
一串字符,以.表示结束。
输出判断的结果,以yes或者no表示。
abccba.df
yes
#include <bits/stdc++.h> using namespace std; int main(){ char a[101],k; int len = 0; while (true){ cin >> k; if (k != ‘.‘) a[len] = k; else break; len++; } if (len % 2 == 0){ for (int i = 0;i < len / 2;i++){ if (a[i] != a[len - i - 1]){ cout << "no"; return 0; } } cout << "yes"; } else{ for (int i = 0;i <= len / 2;i++){ if (a[i] != a[len - i - 1]){ cout << "no"; return 0; } } cout << "yes"; } return 0; }
原文:https://www.cnblogs.com/linyiweiblog/p/14458658.html