0
清理此代码的一般技巧? 只是似乎我可以完成没有做所有检查的任务..严格相同的数组输入
谢谢!
txt书问题: (完全相同的数组)两个数组list1 []和list2 []如果它们具有相同的长度,并且每个[i]的list1 []等于list2 [],它们是完全相同的。
写如果list1的和list2中严格相同使用下面的头
bool strictlyEqual(const int list1[], const int list2[], int size)
收件,提示用户输入整数和显示器的两个列表两者是否是严格相同的测试程序,则返回true的函数。样品运行如下。请注意,输入中的第一个数字表示列表中元素的数量。这个号码不是列表中的一部分。假设该列表的大小是最大
我的代码:
#include <iostream>
using namespace std;
bool strictlyEqual(int const list1[], int const list2[], int size);
bool strictlyEqual (int x1[], int x2[], int n)
{
int f=0; int i;
for (i =1; i<=n; i++)
{
if (x1[i] != x2[])
{
// breaks loop
f=1;
break;
}
}
if (f==0)
return (true);
else
return(false);
}
int main()
cout << "enter list1: " << endl;
int list1[20], i;
cin >> list1[0];
for (i=1; i<= list1[0]; i++)
cin>> list1[i];
cout <<"enter the list2" << endl;
int list2[20];
cin >> list2[0];
for (i=1; i<= list2[0]; i++)
cin >> list2[i];
if (list1[0] == list2[0]
{
int size = list2[0];
bool v=strictlyEqual(list1, list2, size);
if (v== true)
cout << "identical" << endl;
else
cout << "not identical " << endl;
}
return 0;
}
您应该在数组元素'5 5 4 3 2 1'之间添加空格。 –
@ HiI'mFrogatto谢谢!任何一般的技巧来清理此代码?只是似乎有点凌乱.. – walletfiber
仍然我不明白你的问题是什么?错误? –