• 判断一个序列是否是另一个序列的前缀


    // test13.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    #include<vector>
    #include<string>
    #include<cstring>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	vector<int> longNum;
    	vector<int> shortNum;
    	int num,flag=1;
    	cout << "请输入长序列:" << endl;
    	while (cin >> num)
    	{
    		longNum.push_back(num);
    		if (getchar() == '
    ')
    			break;
    	}
    
    	cout << "请输入短序列:" << endl;
    	while (cin >> num)
    	{
    		shortNum.push_back(num);
    		if (getchar() == '
    ')
    			break;
    	}
    
    	
    
    	for (auto it = longNum.begin(); it != longNum.end(); it++)
    	{
    		cout << *it << " ";
    	}cout << endl;
    
    	for (auto it = shortNum.begin(); it != shortNum.end(); it++)
    	{
    		cout << *it << " " ;
    	}cout << endl;
    
    
    	for (int i = 0; i < shortNum.size(); i++)
    	{
    		if (shortNum[i] != longNum[i])
    		{
    			flag = 0;
    			break;
    		}
    	}
    	if (flag == 1)
    		cout << "短序列是长序列的前缀" << endl;
    	else
    		cout << "短序列不是长序列的前缀" << endl;
    
    }
  • 相关阅读:
    HDUOJ---2152
    HDUOJ ---悼念512汶川大地震遇难同胞——来生一起走
    HDUOJ --2566
    HDUOJ ----1709
    HDUOJ---1171
    HDUOJ ------1398
    catalan---卡特兰数(小结)
    向前字典排序
    HDUOJ--Holding Bin-Laden Captive!
    HDUOJ----Ignatius and the Princess III
  • 原文地址:https://www.cnblogs.com/wdan2016/p/5914602.html
Copyright © 2020-2023  润新知