Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #define INPUT_FILE "input.txt"
- #define OUTPUT_FILE "output.txt"
- using namespace std;
- int main()
- {
- bool end = false;
- int N; //numero di valori
- int X; //numero da confrontare
- int y; //valore da leggere
- fstream infile, outfile;
- infile.open(INPUT_FILE,fstream::in);
- outfile.open(OUTPUT_FILE,fstream::out);
- if (!infile.is_open())
- {
- cerr << "errore apertura file input " << INPUT_FILE << endl;
- return -1;
- }
- if (!outfile.is_open())
- {
- cerr << "errore apertura file output " << OUTPUT_FILE << endl;
- return -1;
- }
- while (!end)
- {
- infile >> N >> X;
- if (infile.eof())
- {
- cout << "fine input, bestia!" << endl;
- end = true;
- }
- else if (infile.fail())
- {
- cerr << "errore lettura file input " << INPUT_FILE << endl;
- end = true;
- }
- else
- {
- int cont = 0;
- for (int i=0; i<N; i++)
- {
- infile >> y;
- if (y > X) {
- cont++;
- }
- }
- int vett[cont] = {0};
- for (int i=0; i<N; i++)
- {
- infile >> y;
- if (y > X) {
- vett[i] = y;
- }
- }
- outfile << cont << " ";
- for (int i=0; i<cont; i++ ) {
- outfile << vett[i] << " ";
- }
- outfile << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement