题解 | 小美的排列询问

小美的排列询问

https://www.nowcoder.com/practice/2a9dd3471bf1475aab0117a58d9d45d4

//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int x, y;
  cin >> x >> y;
  if (find(a.begin(), a.end(), x) != a.end()){//----------这个可以不要的
    int index = static_cast<int>(find(a.begin(), a.end(), x) - a.begin());//-------获取索引
    if (index != 0 && a[index - 1] == y){//-----是否在前
      cout << "Yes";
      return 0;
    }
    if (index != n - 1 && a[index + 1] == y){//-------是否在后
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}
// 64 位输出请用 printf("%lld")

#写题解领奖励##牛客春招刷题训练营#
全部评论

相关推荐

12-06 16:40
已编辑
山西大学 测试工程师
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务