赢或输问题 [英] WIN or LOSE question

查看:66
本文介绍了赢或输问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<bits/stdc++.h> 
using namespace std; 
  
// Returns true if arr1[0..n-1] and arr2[0..m-1] 
// contain same elements. 
bool areEqual(int arr1[], int arr2[], int n, int m) 
{ 
    // If lengths of array are not equal means 
    // array are not equal 
    if (n != m) 
        return false; 
  
    // Sort both arrays 
    sort(arr1, arr1+n); 
    sort(arr2, arr2+m); 
  
    // Linearly compare elements 
    for (int i=0; i<n; i++) 
         if (arr1[i] != arr2[i]) 
            return false; 
  
    // If all elements were same. 
    return true; 
} 
  
// Driver Code 
int main() 
{ 
    int arr1[] = { 3, 5, 2, 5, 2}; 
    int arr2[] = { 2, 3, 5, 5, 2}; 
    int n = sizeof(arr1)/sizeof(int); 
    int m = sizeof(arr2)/sizeof(int); 
  
    if (areEqual(arr1, arr2, n, m)) 
        cout << "Yes"; 
    else
        cout << "No"; 
    return 0; 
} 



而不是预定义的数组,即2我已经向用户询问要定义多少数组及其值



我尝试了什么:



i得到了解决方案但无法根据用户输入定义数组。


instead of predefined number of array i.e 2 i have ask from user how many array to define and their values

What I have tried:

i got the solution but unable to define array based on user input.

推荐答案

int arraySize;
cin >> arraySize;
int array = new int[arraySize];


我们非常愿意帮助那些被困的人:但是这并不意味着我们在这里为你做这一切!我们不能做所有的工作,你要么得到报酬,要么是你的成绩的一部分,我们为你做这一切都不公平。



所以我们需要你做这项工作,当你遇到困难时我们会帮助你。这并不意味着我们会为您提供一步一步的解决方案!

首先解释您目前的位置,以及流程的下一步是什么。然后告诉我们你试图让下一步工作,以及当你做了什么时发生了什么。



只是把你的作业丢给我们说我得到了解决方案但是......这里没有切冰。
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just dumping your homework on us and saying "I got the solution but ..." doesn't cut the ice here.


这篇关于赢或输问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆