512 - Spreadsheet Tracking

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
hrkns
New poster
Posts: 2
Joined: Sun Jan 25, 2015 3:30 pm

Re: 512 - Spreadsheet Tracking

Post by hrkns »

.. well, i don't know the reason of WA for this code, can somebody helps?

Code: Select all

#include<iostream>
#include<vector>

using namespace std;

typedef struct
{
	int i, j;
}item;

int main()
{
	int n, m, o, x = 1, z, val;
	int x1, y1, x2, y2;
	string s;
	do
	{
		cin >> n >> m;
		if(n!=0&&m!=0)
		{
			if(x>1)cout << endl;
			vector< vector<item> > v(n+1, vector<item>(m+1));
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= m; j++)
				{
					v[i][j].i = i;
					v[i][j].j = j;
				}
			cin >>o;
			while(o--)
			{
				cin >> s;
				if(s=="DR")
				{
					cin >> z;
					for (int i = 0; i < z; i++)
					{
						cin >> val;
						v.erase(v.begin() + val - i);
						n--;
					}
				}
				else if(s=="DC")
				{
					cin >> z;
					for (int i = 0; i < z; i++)
					{
						cin >> val;
						for (int j = 1; j <= n; j++)
							v[j].erase(v[j].begin()+val-i);
						m--;
					}
				}
				else if(s=="IC")
				{
					item aux;
					aux.i = aux.j = -1;
					cin >> z;
					for (int i = 0; i < z; i++)
					{
						cin >> val;
						for (int j = 1; j <= n; j++)
							v[j].insert(v[j].begin()+val+i, aux);
						m++;
					}
				}
				else if(s=="IR")
				{
					item aux;
					aux.i = aux.j = -1;
					cin >> z;
					for (int i = 0; i < z; i++)
					{
						cin >> val;
						vector<item> vaux(m+1, aux);
						v.insert(v.begin()+val+i, vaux);
						n++;
					}
				}
				else if(s=="EX")
				{
					cin >> x1 >> y1 >> x2 >> y2;
					item aux;
					aux.i = v[x1][y1].i;
					aux.j = v[x1][y1].j;
					v[x1][y1].i=v[x2][y2].i;
					v[x1][y1].j=v[x2][y2].j;
					v[x2][y2].i=aux.i;
					v[x2][y2].j=aux.j;
				}
			}
			/*for (int i = 1; i <= n; i++)
			{
				for (int j = 1; j <= m; j++)
					cout << "(" << v[i][j].i << ", " << v[i][j].j <<  ") ";
				cout << endl;
			}*/
			cout << "Spreadsheet #" << x++ << endl;
			cin >> o;
			int xi, yj, i, j;
			while(o--)
			{
				cin >> xi >> yj;
				i=1;
				bool cond = false;
				while(i <= n && !cond)
				{
					j=1;
					while(j<=m && !cond)
					{
						cond = v[i][j].i==xi&&v[i][j].j==yj;
						if(!cond)j++;
					}
					if(!cond) i++;
				}
				cout << "Cell data in (" << xi << "," << yj << ") ";
				if(cond) cout << "moved to (" << i << "," << j << ")" << endl;
				else cout << "GONE" << endl;
			}
		}
	}while(n!=0&&m!=0);
	return 0;
}
learning english...
Post Reply

Return to “Volume 5 (500-599)”