文章

49

粉丝

90

获赞

90

访问

37.9k

头像
C++
P1869 云南大学机试题
发布于2024年3月17日 19:36
阅读数 595

  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. bool is_all_even_or_all_odd(vector<int> v)
  5. {
  6. if (v.front() % 2 == 0)
  7. {
  8. for (auto t : v)
  9. {
  10. if (t % 2 != 0)
  11. {
  12. return false;
  13. }
  14. }
  15. }
  16. else
  17. {
  18. for (auto t : v)
  19. {
  20. if (t % 2 == 0)
  21. {
  22. return false;
  23. }
  24. }
  25. }
  26. return true;
  27. }
  28. int main()
  29. {
  30. int n;
  31. cin >> n;
  32. for (int i = 0; i < n; i++)
  33. {
  34. int t;
  35. cin >> t;
  36. vector<int> v(t);
  37. for (int i = 0; i < t; i++)
  38. {
  39. int x;
  40. cin >> x;
  41. v[i] = x;
  42. }
  43. if (is_all_even_or_all_odd(v))
  44. {
  45. cout << "YES" << endl;
  46. }
  47. else
  48. {
  49. cout << "NO" << endl;
  50. }
  51. }
  52. return 0;
  53. }

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发