比较两个数组是否具有相反的相同字符。 (C ++) [英] Compare if two arrays have same characters in reverse order. (C++)

查看:69
本文介绍了比较两个数组是否具有相反的相同字符。 (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int isReverse(char array_a [],char array_b [],int size){





}



//我知道如何做比较部分,但我坚持反向订购部分

//我不知道如何检查字符数组是否具有相反的相同字符



我尝试过的方法:



int isReverse(char array_a [],char array_b [],int size){



for(int i = 0; i< size ; i ++)

{

if(array_a [i]!= array_b [i])

返回false;

else

返回true;

}

int isReverse (char array_a[], char array_b[], int size) {


}

//I know how to do the compare part but I'm stuck on the reverse order part
// I'm don't know how to check char arrays if they have the same character in reverse order

What I have tried:

int isReverse (char array_a[], char array_b[], int size) {

for (int i=0; i < size; i++)
{
if (array_a[i] != array_b[i])
return false;
else
return true;
}

推荐答案

缺少提示:

a)使用从最后一个元素开始的额外向下计数器

b)一个差异意味着结果为假,但是只有在完成所有操作后才为真

c )写一些测试数据来调用你的函数
missing tips:
a) use an extra downcounter which starts at the last element
b) one difference means the result is false, BUT true only when all done
c) write some test data to call your function


引用:

我知道怎么做比较部分,但是我坚持反向订购部分

我不知道怎么检查char数组是否有相反的相同字符

I know how to do the compare part but I'm stuck on the reverse order part
I'm don't know how to check char arrays if they have the same character in reverse order



拿一张纸和铅笔试着手工解决。

选择一个样本,写下2个数组,写每个字符的位置,制作一个包含字符位置的表,你必须检查两个数组。

用另一个大小写另一个例子。

找到它之间的数学关系char检查两个数组中的位置。这是非常简单的数学,如果你不能处理它,和老师谈谈,因为你有一个大问题。



我们不做你的HomeWork。

HomeWork不会在乞求别人做你的工作时测试你的技能,它会让你思考并帮助你的老师检查你对你所学课程的理解。还有你在应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会​​如何。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并做出必要的调整以适应你的实际问题。


Take a sheet of paper and pencil and try to solve by hand.
Choose a sample, write the 2 arrays, write the position of each char, make a table with positions of chars you have to check in both arrays.
Write another example with another size.
Find the mathematical relation between the char check positions in both arrays. This is very simple maths, if you can't deal with it, have a talk with your teacher, because you have a big problem.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.


想想它:它并不复杂。

首先检查长度:如果它们是不同的,它们不匹配。

没关系,将一个数组的最后一个元素与另一个数组的第一个元素进行比较。这很容易 x [0] vs y [0 + len - 1]

如果它们是相同的,将一个数组的最后一个元素与另一个数组的第二个元素进行比较。这很容易 x [1] vs y [1 + len - 1]

和等等,直到你完成所有这些。



一点点想法会告诉你如何在循环中做到这一点......
Think abut it: it's not complicated.
Start by checking the lengths: if they are different, they don't match.
It that's fine, compare the last element of one array with the first element of the other. That's easy x[0] vs y[0 + len - 1]
If they are the same, compare the last but one element of one array with the second element of the other. That's easy x[1] vs y[1 + len - 1]
And so on, until you have done them all.

And a little bit of thought will show you how to do that in a loop ...


这篇关于比较两个数组是否具有相反的相同字符。 (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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