When i try to run it says that my program doesnt work anymore?(sry for my bad english).
Problem's condition:
Some pirates have a map that shows where is the treasure.
In the map is written the number of operations(for example one operation says for the pirates to move y steps in the x directions ).
Once the pirates follow all the operations, they find the treasure.
There are two types of of directions, the direction 1 and direction 2.
For 1, (a and b are coordinates, their current coordinates)
if (x[t]==1)
a=a;
b=b+y[t];(y[t] is the number of steps)
For 2,
if (x[t]==2)
a=a;
b=b-y[t];.
You must make a program which shows you where is the tresure, in other words, the final position of the pirates.
You take the place where the pirates are as the coordinates (0 , 0)
Input will be the number of operations=m , then the direction with the steps, then again the direction with the steps.... this is done m times since m is the number of operations.
Output: will be the final coordinates.
Example:
Input:
3 1 2 2 3 1 5
(here 1 2, 2 3 and 1 5 are the pairs);
Output:
0 5
;
Of course that a will be 0 so dont ask me why i put in general a since it will be always 0.
Well thats because the actual problem has more than 2 direction, but 8 and there a is too changed.
Please show me where is the mistake?
Thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <fstream>
#include <iostream>
using namespace std;
int a, b;
void finding(int i, int x[], int y[]){
a=0;
b=0;
for (int t = 0; t<i; t++)
{
if (x[t]==1)
a=a;
b=b+y[t];
if (x[t]==2)
a=a;
b=b-y[t];}
}
int main()
{
ifstream fin("comori.in");
ofstream fout("comori.out");
int m;
fin>>m;
int e[m], r[m];
for (int w = 0 ; w<m; w++ ){
fin>>e[w] >>r[w];}
finding(m, e, r);
fout<<a<<b;
fout.close ();
fin.close ();
}
|