Browse Source

字符串排序

zj 5 years ago
parent
commit
342c37f240
1 changed files with 23 additions and 0 deletions
  1. 23 0
      F.cpp

+ 23 - 0
F.cpp

@@ -0,0 +1,23 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+bool ok(const string &s) {
+    if (s.length() == 0 || s.length() % 2 != 0) return false;
+    for (int i = 0; i < s.length() / 2; i++)
+        if (s[i] != s[s.length() - 1 - i]) return false;
+    return true;
+}
+
+int main(int argc, char const *argv[]) {
+    int n;
+    cin >> n;
+    while (n--) {
+        string s;
+        cin >> s;
+        while (ok(s)) s = s.substr(0, s.length() / 2);
+        cout << s.length() << endl;
+
+    }
+    return 0;
+}