zoukankan      html  css  js  c++  java
  • PAT 1077

    簡單題,用C++寫了... 

    需要注意的是,cin了之後不會把 吃掉,需要再getchar一次才能夠吃掉 ,然後接着geline才正確

    感覺沒什麼美感... 

     1 #include <vector>
     2 #include <iostream>
     3 #include <string>
     4 #include <algorithm>
     5 #include <limits>
     6 #include <cstdio>
     7 
     8 using namespace std;
     9 
    10 int main(){
    11     int N;
    12     cin >> N;
    13     getchar();
    14 
    15     vector<string> lines;
    16     int shortest = 0x7fffffff;
    17     for (int i = 0; i < N; i++){
    18         string str;
    19         getline(cin, str);
    20 
    21         if (str.size() < shortest)
    22             shortest = str.size();
    23 
    24         lines.push_back(str);
    25     }
    26 
    27     int common_len = 0;
    28     for (int i = 0; i < shortest; i++){
    29         char ch = lines[0][lines[0].size() - i - 1];
    30 
    31         int cnt = 1;
    32         for (int j = 1; j < lines.size(); j++){
    33             string cur_str = lines[j];
    34             if (cur_str[cur_str.size() - i - 1] != ch)
    35                 break;
    36             cnt++;
    37         }
    38 
    39         if (cnt == lines.size())
    40             common_len++;
    41         else
    42             break;
    43     }
    44 
    45     if (common_len == 0)
    46         cout << "nai" << endl;
    47     else{
    48         string res = lines[0].substr(lines[0].size() - common_len, lines[0].size());
    49         cout << res << endl;
    50     }
    51 
    52     return 0;
    53 }
  • 相关阅读:
    Activator.CreateInstance 反射实例化对象
    MVC Form提交
    Redis 下载
    List<T> 序列化与反序列化
    快速反射DataTable
    数据库特性
    javascript判断文件大小
    MD5
    HttpHelper
    cacheHelper
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4080115.html
Copyright © 2011-2022 走看看