Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32784
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 360
  • 用 户 组: 普通用户
  • 注册时间: 2021-09-17 18:39
文章分类

全部博文(35)

文章存档

2021年(35)

我的朋友

分类: C/C++

2021-09-22 18:03:47

C++不定数据长度输入
#include
#include
using std::vector;
using std::string;
using std::cin;
using std::cout;

int LCS(string s1, string s2) {
    int res = 0;
    int a = 0;
    int b = 0;
    for (int i = 0, j = 0; i < s1.size() && j < s2.size(); i++, j++) {
        if (s1[i] == s2[j])
            res++;
        else
            break;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector s;
    string tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        s.push_back(tmp);
    }
    vector> num;
    int temp;
    int index = 0;
   
    while (cin.get()){
        cin >> temp;
        num[index][0] = int(temp);
        cin >> temp;
        num[index][1] = int(temp);
        //num[index][1].push_back(temp);
    }

    for (int i = 0; i < num.size(); i++) {
        int a = num[i][0];
        int b = num[i][1];
        int res = LCS(s[a], s[b]);
        cout << res;
    }
   
}
阅读(771) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~