Hi, can some1 help me, with writting a program, which needs to find out if massive is simmetrical, for ex 1 2 2 1, 1 2 3 3 2 1, and etc
I know all functions like which needs to write, read from file and etc, just need a simple algorithm, that can find if massive is simmetrical.
im using fstream library , reading from text file, so if u can give me the simplest one, thanks!
What exactly do you mean by "in massive"? Do you mean that the numbers will have spaces in between them?
If that is the case I would say the best possible solution is to put it into a std::string (If it isn't already, not exactly sure how you are getting the input and storing it) and then do the palindrome test on that string.
Though I am just taking wild guesses now because I really don't know what you are asking for, and have no idea how your program is structured or what the program is. If you could give us your source code (Or the relevant parts) that would be great so we can get a idea of what you are trying to do.
return 0;
}
void read (int T[], int & n)
{
ifstream fd(CDfv);
fd >> n; //how many numbers there is
for (int i=0; i<n; i++)
{
// this is numbers massive, numbers are seperated from each other like as i said 1 2 3 3 2 1
fd >> T[i];
}
fd.close();
}
// now i need second function which will show if numbers in T massive are simmetrical
Ignore the fact that it's a number. Treat it like a string instead. Then see if the string is symmetrical by comparing the i'th character with the size()-1-i'th.
can u give example? i know what u mean, but i cant write it...i need like compare first one and the last one and do it with second and etc, but... i dont know how to code it
{
int first = 0;
int last = n–1;
while (first < last) {
if (s[first]!=s[last]) return false;
++first;
––last;
}
return true;
}
idk smthing like this, its for arrays
i need to use fstream, read numbers from file, im not using array, well im pretty bad since im learning programing like only for 2 weeks...so sry if i missunderstood smthing