#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
struct transaction
{
string item;
int cost;
};
int main()
{
transaction buy[100];
transaction sell[100];
int price;
int w, s;
ifstream myfile.open ("messageBoard.txt");
ofstream results.open ("results.txt");
string line;
}
myfile >> getline(myfile, buy[w], '\n');
if
if(!myfile)
{
cout<<"Error opening input file"<<endl;
return -1;
}
while(myfile, line)
{
if(line.find("wanted") != string::npos);
{
getline(myfile,buy[w].item);
getline(myfile,price);
stringstream(price) >> buy[w].cost;
}
}
while(myfile, line)
{
if(line.find("for sale") != string::npos);
{
getline(myfile,buy[s].item);
getline(myfile,price);
stringstream(price) >> buy[s].cost;
}
}
for(w=0; w<100; w++)
{
for(s=0; s<100; s++)
{
if(buy[w].item == sell[s].item && buy[w].cost <= sell[s].cost)
if (results.is_open())
{
results << buy[w] << " matches " << sell[s] << "\n";
}
else
cout << "Unable to open output file." << endl;
buy[w] = 0;
sell[s] = 0;
}
}
results.close();
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGlvbWFuaXA+CiNpbmNsdWRlPGZzdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8c3N0cmVhbT4KI2luY2x1ZGU8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCB0cmFuc2FjdGlvbgp7CiAgICBzdHJpbmcgaXRlbTsKICAgIGludCBjb3N0Owp9OwoKaW50IG1haW4oKQp7CiAgICB0cmFuc2FjdGlvbiBidXlbMTAwXTsKICAgIHRyYW5zYWN0aW9uIHNlbGxbMTAwXTsKICAgIGludCBwcmljZTsKICAgIGludCB3LCBzOwogICAgaWZzdHJlYW0gbXlmaWxlLm9wZW4gKCJtZXNzYWdlQm9hcmQudHh0Iik7CiAgICBvZnN0cmVhbSByZXN1bHRzLm9wZW4gKCJyZXN1bHRzLnR4dCIpOwogICAgc3RyaW5nIGxpbmU7Cgp9CiAgIG15ZmlsZSA+PiBnZXRsaW5lKG15ZmlsZSwgYnV5W3ddLCAnXG4nKTsKICAgICAgICBpZgogICAgaWYoIW15ZmlsZSkKICAgICAgewogICAgICAgIGNvdXQ8PCJFcnJvciBvcGVuaW5nIGlucHV0IGZpbGUiPDxlbmRsOwogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICAgIHdoaWxlKG15ZmlsZSwgbGluZSkKICAgICAgICB7CiAgICAgICAgICAgIGlmKGxpbmUuZmluZCgid2FudGVkIikgIT0gc3RyaW5nOjpucG9zKTsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZ2V0bGluZShteWZpbGUsYnV5W3ddLml0ZW0pOwogICAgICAgICAgICAgICAgZ2V0bGluZShteWZpbGUscHJpY2UpOwogICAgICAgICAgICAgICAgc3RyaW5nc3RyZWFtKHByaWNlKSA+PiBidXlbd10uY29zdDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZShteWZpbGUsIGxpbmUpCiAgICAgICAgewogICAgICAgICAgICBpZihsaW5lLmZpbmQoImZvciBzYWxlIikgIT0gc3RyaW5nOjpucG9zKTsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZ2V0bGluZShteWZpbGUsYnV5W3NdLml0ZW0pOwogICAgICAgICAgICAgICAgZ2V0bGluZShteWZpbGUscHJpY2UpOwogICAgICAgICAgICAgICAgc3RyaW5nc3RyZWFtKHByaWNlKSA+PiBidXlbc10uY29zdDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgZm9yKHc9MDsgdzwxMDA7IHcrKykKICAgIHsKICAgICAgICBmb3Iocz0wOyBzPDEwMDsgcysrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYnV5W3ddLml0ZW0gPT0gc2VsbFtzXS5pdGVtICYmIGJ1eVt3XS5jb3N0IDw9IHNlbGxbc10uY29zdCkKICAgICAgICAgICAgICAgIGlmIChyZXN1bHRzLmlzX29wZW4oKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICByZXN1bHRzIDw8IGJ1eVt3XSA8PCAiIG1hdGNoZXMgIiA8PCBzZWxsW3NdIDw8ICJcbiI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgY291dCA8PCAiVW5hYmxlIHRvIG9wZW4gb3V0cHV0IGZpbGUuIiA8PCBlbmRsOwogICAgICAgICAgICAgICAgYnV5W3ddID0gMDsKICAgICAgICAgICAgICAgIHNlbGxbc10gPSAwOwogICAgICAgIH0KICAgIH0KICAgIHJlc3VsdHMuY2xvc2UoKTsKcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main()’:
prog.cpp:22:20: error: expected initializer before ‘.’ token
ifstream myfile.open ("messageBoard.txt");
^
prog.cpp:23:21: error: expected initializer before ‘.’ token
ofstream results.open ("results.txt");
^
prog.cpp:18:17: warning: unused variable ‘buy’ [-Wunused-variable]
transaction buy[100];
^
prog.cpp:19:17: warning: unused variable ‘sell’ [-Wunused-variable]
transaction sell[100];
^
prog.cpp:20:9: warning: unused variable ‘price’ [-Wunused-variable]
int price;
^
prog.cpp:21:9: warning: unused variable ‘w’ [-Wunused-variable]
int w, s;
^
prog.cpp:21:12: warning: unused variable ‘s’ [-Wunused-variable]
int w, s;
^
prog.cpp: At global scope:
prog.cpp:27:4: error: ‘myfile’ does not name a type
myfile >> getline(myfile, buy[w], '\n');
^
prog.cpp:28:9: error: expected unqualified-id before ‘if’
if
^
prog.cpp:34:9: error: expected unqualified-id before ‘while’
while(myfile, line)
^