zoukankan      html  css  js  c++  java
  • 判断一个序列是否是另一个序列的前缀

    // 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;
    
    }
  • 相关阅读:
    Queries about less or equal elements CodeForces
    Session in BSU CodeForces
    基环树
    骑士 HYSBZ
    Valid BFS? CodeForces
    Trips CodeForces
    The writing on the wall 南京网络赛2018B题
    Building a Space Station
    Constructing Roads
    Networking
  • 原文地址:https://www.cnblogs.com/wdan2016/p/5914602.html
Copyright © 2011-2022 走看看