【PAT甲级】1077. Kuchiguse (20)
来源:互联网 发布:淘宝卖什么好 编辑:程序博客网 时间:2024/06/05 07:56
注意:1. getline()可能get到空行,需要过滤一下2. 头文件algorithm中的reverse可以对字符串进行反转
#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;int findMinLength(vector<string> v);int main() { int n; cin >> n; vector<string> v; string line; for (int i = 0; i < n; i++) { getline(cin, line); if (line.empty()) { i--; continue;////////// } reverse(line.begin(), line.end()); v.push_back(line); } int m = findMinLength(v); int count = 0; bool flag = true; for (int i = 0; i < m && flag; i++) { char c = v[0].at(count); for (int j = 0; j < n; j++) { if (c != v[j].at(count)){ flag = false; break; } } if (flag) count++; } if (!count) cout << "nai" << endl; else { reverse(v[0].begin(), v[0].end()); cout << v[0].substr(v[0].length() - count) << endl;; } return 0;}int findMinLength(vector<string> v) { int min = v[0].length(); for (int i = 0; i < v.size(); i++) { if (v[i].length() < min) min = v[i].length(); } return min;}
阅读全文
0 0
- PAT甲级.1077. Kuchiguse (20)
- 1077. Kuchiguse (20) PAT甲级
- 【PAT甲级】1077. Kuchiguse (20)
- PAT 甲级 1077. Kuchiguse (20)
- PAT 甲级 1077. Kuchiguse
- 1077. Kuchiguse (20)-PAT甲级真题
- PAT(甲级)1077. Kuchiguse (20)
- [转]PAT甲级练习1077. Kuchiguse (20)
- 牛客网 PAT(甲级) 1012Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- pat 1077. Kuchiguse (20)
- PAT 1077. Kuchiguse (20)
- 【PAT】1077. Kuchiguse (20)
- HDU3317---Fibonacci Numbers(矩阵快速幂+pow+log)
- Java IO复习
- Jenkins+SVN+tomcat+Batch Command(Java web项目打包部署运行)
- The Closeable, Flushable, Readable, and Appendable interfaces
- 第十九周(Minimum Number of Arrows to Burst Balloons)
- 【PAT甲级】1077. Kuchiguse (20)
- VC 通过mshtml.dll获取ie版本号
- tesseract-ocr
- 《Hadoop生态》——第二章 数据库与数据管理——HBase
- Novasmobi隱私政策
- 复习nio
- linux 命令: ps 和 top
- mybatis引入配置文件
- 初识Retrofit