Help to find if massive is symmetrical

Oct 30, 2014 at 2:04pm
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!

Last edited on Oct 30, 2014 at 2:14pm
Oct 30, 2014 at 2:32pm
Search with word "palindrome".
Oct 30, 2014 at 3:04pm
i know that and i could search if its polindrome for whole number, but not individual numbers in massive as i said 1 2 3 3 2 1 and etc...
Oct 30, 2014 at 3:48pm
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.
Oct 30, 2014 at 5:13pm
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const char CDfv[] = "Duomenys.txt";
const char CRfv[] = "Rezultatai.txt";
const int CMax = 100;
void read (int T[], int & n)

using namespace std;

int main()
{
int T[CMax];
int n;

read (T, n);

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
Oct 30, 2014 at 6:35pm
can some1 help?
Oct 30, 2014 at 6:41pm
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.
Oct 30, 2014 at 7:08pm
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
Oct 30, 2014 at 10:24pm
How would you test a "regular" palindrome?
Oct 30, 2014 at 11:24pm
{
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
Oct 30, 2014 at 11:45pm
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
Topic archived. No new replies allowed.