Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct pt
- {
- int x, y;
- pt()
- {
- }
- pt(int x, int y): x(x), y(y)
- {
- }
- };
- istream& operator>> (istream& in, pt& p)
- {
- char c;
- return in >> c >> p.x >> c >> p.y >> c;
- }
- ostream& operator<< (ostream& out, const pt& p)
- {
- return out << "(" << p.x << ", " << p.y << ")";
- }
- template<typename X>
- void read(X *mas, int a, int b)
- {
- for (int i = 0; i<a; i++)
- {
- for (int j = 0; j<b; j++)
- {
- cin >> mas[i][j];
- }
- }
- }
- template<typename X>
- void print(X *mas, int a, int b)
- {
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- cout << mas[i][j] << ' ';
- }
- cout << endl;
- }
- }
- template <typename X>
- void print_snake(X *mas, int a, int b)
- {
- for (int i = 0; i< a; i++)
- {
- if (i % 2 == 0)
- {
- for (int j = 0; j < b; j++)
- {
- cout << mas[i][j] << ' ';
- }
- }
- else
- {
- for (int j = 0; j < b; j++)
- {
- cout << mas[i][b - j - 1] << ' ';
- }
- }
- }
- cout << endl;
- }
- int main()
- {
- pt mas[100][100];
- int a, b;
- cout<<"enter the number of rows and columns"<<endl;
- cin >> a >> b;
- cout<<"enter the matrix row by row"<<endl;
- read(mas, a, b);
- cout<<"your matrix is:" << endl;
- print(mas, a, b);
- cout<<"your matrix in snake order:" << endl;
- print_snake(mas, a, b);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment