[ create a new paste ] login | about

Link: http://codepad.org/DyGGANgf    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Mar 9:
//StockExchange
#include <iostream>
#include <conio.h>

using namespace std;
int main()
{
	int testcase, i, j, n;
	freopen("Testcase.txt", "r", stdin);
	cin >> testcase;
	for(int i = 1; i <= testcase; i++)
	{
		cin >> n;
		int sum = 0; 
		int price[30];
		for(j = 0; j < n; j++)
			cin >> price[j];
		
		for(j = 0; j < n; j++)
		{
			int sell = 0, buy = 0;
			int k, max = 0, posMax;
			for(k = j; k < n; k++)
				if(max < price[k])
				{
					max = price[k];
					posMax = k;
				}
			for(k = j; k < posMax; k++)
			{
				buy += price[k];
			}
			sell = (k-j) * price[posMax];
			sum += (sell - buy);
			j = k;
		}

		cout << "#" << i << " " << sum << endl;
	}
	getch();
	return 0;
}


Output:
1
2
3
4
Line 18: error: conio.h: No such file or directory
In function 'int main()':
Line 40: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: