/* helder.correia@fe.up.pt
 * Data: 28-02-2005
 *
 * aula prática 1 (grupo 2, ponto 3)
 */

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[]) {
  int num = 0;
  
  if (argc < 3) {
    cerr << "Sintaxe: " << argv[0] << " operacao ficheiro_de_valores" << endl;
    return -1;
  }

  ifstream fvalores (argv[2]);
  if (!fvalores) {
    cerr << "Erro ao abrir ficheiro " << argv[2] << endl;
    return -1;
  }

  while (!fvalores.eof()) {
    fvalores >> num; 

    // par?
    if (string(argv[1]) == "par") {
      if (num%2 == 0) cout << num << endl;

    // impar?
    } else if (string(argv[1]) == "impar") {
      if (num%2) cout << num << endl;

    // positivo?
    } else if (string(argv[1]) == "pos")  {  
      if (num > 0) cout << num << endl;

    // erro
    } else { 
      cerr << "Comando inválido!" << endl; 
      return -1;
    }
  }
  return 0;
}

