コード例 #1
0
int main()
{
    fin.open("uppgift1.txt");
    fout.open("output3.txt");

    string word;
    int howMany=0;
    while(fin >> word >> ws)
    {
        cleanUp(word);
        words[word]++;
        howMany++;
    }
    int Unique = 0;

    for(map<string, int>::iterator it = words.begin(); it != words.end(); ++it)
         Unique++;



    fout << "Number of words in the file = " << howMany << endl;
    fout << "Number of unique words in the file = " << Unique << endl  << endl;
    fout << "Frequency table sorted alphabetically ..." << endl << endl;

    for(map<string, int>::iterator it = words.begin(); it != words.end(); ++it)
    {
        pair<int, string> p;
        p.first = it->second;
        p.second = it->first;

        toSort.push_back(p);
        fout <<left << setw (20) << it->first << setw (24) << it->second << endl;
    }



    sort(toSort.begin(), toSort.end());
    reverse(toSort.begin(), toSort.end());
    fout << endl << endl << "Frequency table sorted by frequence ..." << endl << endl;
  //  cout << "Frekventiell ordning: " << endl;
    for(vector< pair<int, string> >::iterator ite = toSort.begin(); ite != toSort.end(); ++ite)
    {
        fout << left << setw (20) << ite->second << setw (24) << ite->first << endl;
    }

    fin.close();
    fout.close();

    return 0;
}
コード例 #2
0
ファイル: salti.cpp プロジェクト: FreCap/Algorithm-solutions
int main(){
	int N;    
	in.open("input.txt"); out.open("output.txt");
	in >> N;
	
	int count = 0;
	for(int i=0;i<=30;i++){
		if(N&(1<<i))
			count++;
	}
		
	out<<count;
	return 0;
}
コード例 #3
0
ファイル: c.cpp プロジェクト: veezbo/competitions
int main (void)
{
	in.open("C-large-1.in");
	out.open("output.txt");

	int T;
	in >> T;

	printCase("hello world");

	in.close();
	out.close();
	return 0;
}
コード例 #4
0
ファイル: trace2symbol.cpp プロジェクト: HDFGroup/Replayer
int main(int argc,char *argv[])
{
    string name,oname;
    int i;

    //char ts1[16] = "0.trace";
    //char ts2[12] = "0.symbol";
    //char ts3[10] = "1";


    if (argc != 4)
    {
        cout<<"Usage: trace2symbol inputfile outputfile $n\n"<<endl;
        return 0;
    }

    name.assign(argv[1]);
    //name.assign(ts1);
    oname.assign(argv[2]);
    //oname.assign(ts2);
    for (i=0; i<atoi(argv[3]); i++)
        //for (i=0;i<atoi(ts3);i++)
    {
        fin.open(name.c_str());

        if (fin.fail())
        {
            cout<<"Bad file name!\n"<<endl;
            return 0;
        }

        fout.open(oname.c_str());

        cout<<"Trace2Symbol(V1.0) "<<endl;

        cout << "Dealing with " << name << "...";

        work();

        fin.close();
        fout.close();
        fin.clear();
        fout.clear();

        cout << "Done." << endl;
        name=nextName(name);
        oname=nextName(oname);
    }
    return 0;
}
コード例 #5
0
ファイル: Hashr.cpp プロジェクト: jpc014/Phile_Scanner
string Hashr::getData(string files) {
	if (files != "") {
		dataReader.open(files, std::ios::binary | std::ios::in); //opens files as binary
		dataReader.seekg(0, std::ios::end); // moves curser to the end
		length = dataReader.tellg(); // gets position of the end
		dataReader.seekg(0, std::ios::beg); // moves cursor to beginning
		storage = new char[length]; // creates char array the length of the file
		dataReader.read((char*)storage, length);// stores the bits into storage
		dataReader.close(); //closes file
		std::string data(storage, length);
		return data;
	}
	return "";
}
コード例 #6
0
//ask user to enter file name
string promptUserForFile(ifstream & infile, string prompt ){
    while(true){
        cout << prompt;
        string filename;
        getline(cin, filename);
        infile.open(filename.c_str());
        if(!infile.fail()) return filename;
        infile.clear();
        cout<<"UNABLE TO OPEN FILE! Try again."<<endl;
        if(prompt == ""){
            prompt = "Input filename: ";
        }
    }
}
void get_store_data (ifstream& myfile, string name_array[], float sales_array[][5]) // void function that gets the store data from file
{
    myfile.open("infile.txt");
    string name;
    for (int i = 0; i < 7; i++)
    {
        myfile >> name_array[i];
        for (int x = 0; x < 5; x++)
        {
            myfile >> sales_array[i][x];
            
        }
    }
}
コード例 #8
0
ファイル: utils.cpp プロジェクト: dalinhuang/play-server
ID3_Err dami::openReadableFile(String name, ifstream& file)
{
  if (file.is_open())
  {
    file.close();
  }
  file.open(name.c_str(), ios::in | ios::binary | NOCREATE);
  if (!file)
  {
    return ID3E_NoFile;
  }
    
  return ID3E_NoError;
}
コード例 #9
0
ファイル: FizzBuzz.cpp プロジェクト: timolawl/codeeval
void openFiles(ifstream &ifile_stream, ofstream &ofile_stream) {
	string ifname, ofname;
	cout << "Please enter the name of the input text file: ";
	getline(cin, ifname);
	if(ifname.find(".txt") == string::npos)
		ifname += ".txt";
	ifile_stream.open(ifname.c_str());
	
	cout << "Please enter the name of the output text file where you would like to store the results: ";
	getline(cin, ofname);
	if(ofname.find(".txt") == string::npos)
		ofname += ".txt";
	ofile_stream.open(ofname.c_str());
}
コード例 #10
0
void initStreams()
{
    inputParameters.open("parametersPassive.txt");
    if ( !inputParameters.good() )
    {
        cerr << "File doesn't exist" << endl;
        exit(0);
    }
    parameters.loadParameterFile(inputParameters);
    // WARNING:
    // Base directory and subject name, if are not
    // present in the parameters file, the program will stop suddenly!!!
    // Base directory where the files will be stored
    string baseDir = parameters.find("BaseDir");
    if ( !exists(baseDir) )
        create_directory(baseDir);

    // Subject name
    string subjectName = parameters.find("SubjectName");

    // Principal streams file
    string transformationFileName("transformationFile_");
    string trialFileName("trialFile_");
    string anglesFileName("anglesFile_");
    string responseFileName("responseFile_");

    // Add the subject name to file extension
    transformationFileName	+=string(subjectName)+".txt";
    trialFileName			+=string(subjectName)+".txt";
    anglesFileName			+=string(subjectName)+".txt";
    responseFileName		+=string(subjectName)+".txt";
#ifdef _WIN32
    // Check for output file existence
    /** Transformation file **/
    if ( !fileExists((baseDir+transformationFileName)) )
        transformationFile.open((baseDir+transformationFileName).c_str() );

    /** Trial file **/
    if ( !fileExists((baseDir+trialFileName)) )
        trialFile.open((baseDir+trialFileName).c_str());

    /** Angles file **/
    if ( !fileExists((baseDir+anglesFileName)) )
        anglesFile.open((baseDir+anglesFileName).c_str());

    /** Response file **/
    if ( !fileExists((baseDir+responseFileName)) )
        responseFile.open((baseDir+responseFileName).c_str());
#endif
}
コード例 #11
0
ファイル: borse.cpp プロジェクト: FreCap/Algorithm-solutions
int main(){
	int N;    
	in.open("input.txt"); out.open("output.txt");
	in >> N;

	for(int i=1;i<=N;i++){
		S[t++]=i;
		f(i, N-i);
		t--;
	}
		

	return 0;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: njittam/JhSolver
void open_file(ifstream& file, char newpatern[10])
{
    char filenamedb[] = {'.','\\','d','a','t','a','b','a','s','e','\\'};
    char postfix [] = {'.','t','x','t','\0'};
    char filename[26];
    for (int i = 0; i < 26;i++)
        if (i < 11)
            filename[i] = filenamedb[i];
        else if (i < 21)
            filename[i] = newpatern[i-11];
        else
            filename [i] = postfix[i-21];
    file.open(filename);
}
コード例 #13
0
ファイル: fence.cpp プロジェクト: SummerWish/USACO-solutions
int main()
{
    fin.open("fence.in");
    fout.open("fence.out");

    fin >> f;

    for (int i = 0; i < f; ++i) {
        int a, b; fin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    // count vertex
    
    for (int i = 1; i <= 500; ++i) {
        if (g[i].size() > 0) {
            // make sure from small to large
            sort(g[i].begin(), g[i].end());
            vertexCount++;
        }
    }

    // calculate start vertex
    
    int startVertex;

    for (int i = 1; i <= 500; ++i) {
        if (g[i].size() > 0) {
            startVertex = i;
            break;
        }
    }

    for (int i = 1; i <= 500; ++i) {
        if ((g[i].size() & 1) == 1) {
            startVertex = i;
            break;
        }
    }

    selectVertex(startVertex);

    for (int v : path) {
        fout << v << endl;
    }

    return 0;
}
コード例 #14
0
ファイル: assgnment1.cpp プロジェクト: rgruener/DSA1_ECE164
int main(){

	string ifname,ofname,command;
	cout << "Enter name of input file: ";
	getline(cin, ifname);
	cout << "Enter name of output file: ";
	getline(cin, ofname);
	infile.open(ifname.c_str()); // open takes c string
	outfile.open(ofname.c_str());
	if (infile.is_open())
		process_commands();
	else 
		cerr << "Error while opening input file" << endl;
	return 0;
}
コード例 #15
0
/********************************
** Function: void openInFile(ifstream &fin, string str);
** Description: Open the file and check for errors
**  throw exception if file open fails
**
**
** Parameters: ifstream fin is the file handle
**  string str is the name of the file to open
**
** pre-conditions: fin has been declared, str is a valid file name
** post-conditions: file opened and checked for errors in opening
********************************/
void openInFile(ifstream &fin, char str[])
{
     // can't open empty names
     if (str[1] == '\0') throw (-1);

     // attempt to open file
     fin.open(str);
     if (fin.fail())
     {
          cout << "SOMETHING WENT TERRIBLY WRONG! FAILED TO OPEN INPUT FILE"
               << endl;
          throw(-1);
     }
     return;
}
コード例 #16
0
int main()
{
	in.open(FILE_INPUT);
	out.open(FILE_OUTPUT);
	
	if(!in || !out) return 1;
	
	int N, P;
	in>>N>>P;
	if(P == 1) P_1(N);
	else P_2(N);
	in.close();
	out.close();
	return 0;
}
コード例 #17
0
ファイル: 2_both.cpp プロジェクト: trort/codejam
int main(){
    fin.open("sample.in");
    fout.open("result.out");
    int T;
    fin>>T;
    for(int i=0;i<T;i++){
            fout<<"Case #"<<i+1<<": ";
            cout<<"Case #"<<i+1<<" is runing";
			int ans = _main();
			if(ans >= 0) fout<<ans;
			else if(ans == -1) fout<<"Too Bad";
			else cout<<"error!";
            fout<<endl;
    }
}
コード例 #18
0
/*****************************************************************
* openFile() 
* Parameters: readfile and filename(string) 
* Description: This function opens a file with the name that 
* the user gives and will give a message to the user if the file 
* was opened or not.  
*****************************************************************/
int openFile(ifstream& readFile, string fileName){
	//opens file, puts .txt at the end of it
	readFile.open((fileName + ".txt").c_str());

	if (!readFile){
		cout << fileName << ".txt could not be opened." << endl;
		cout << " " << endl;
		return 1;
	}
	else{
		cout << fileName << ".txt read!" << endl;
	
		return 0;
	}
}
コード例 #19
0
/*
 *  Function:	GetFile
 *  Usage:		GetFile (ifstream inFile)
 *  ----------------------------------
 *  Propts the user to input a file and attempts to open it.  If the file is unopenable then the user is reprompted.
 */
void GetFile (ifstream & inFile) {
	
	cout << "Got the file!" << endl;
		
	while (true) {
		cout << "Enter File Name: ";
		string fileName = GetLine();
		inFile.open(fileName.c_str());
		
		if (!inFile.fail()) break;
		
		inFile.clear();
		cout << "Invalid file name." << endl;
	}
}
コード例 #20
0
int openInput(ifstream& opIn,string unsortfile){
     
     
     opIn.open(unsortfile.c_str());
     
     if(opIn.fail()){
                     
     cout<<unsortfile<<" does not exist.\n";                               
     opIn.close();
     return 0;
    
     }
     
     else return 1;
     }
コード例 #21
0
acc::acc(ifstream& fin)
{
	fin.open("C:\\Users\\Md. Shah Arafat\\overloaded.txt",ios::in);
	if (!fin)
	{
		cout<<endl<<"File Error : File Not Found...." << endl;
		cout<<endl<<"So,No record is created,object is empty or garbage...";
		return;
	}
	fin>>acc_id;
	fin>>name;
	int type;
	fin>>type;
	acc::type = (acc_type) type;
}
コード例 #22
0
int main()
{
	fin.open(FILE_INPUT);
	fout.open(FILE_OUTPUT);

	if(!fin || !fout) return 1;
	fin>>N;
	C.resize(N);
	for(int i = 0; i < N; i++) fin>>C[i];
	fin>>B;
	fact();
	fin.close();
	fout.close();
	return 0;
}
コード例 #23
0
//Function used to read in files and store information in appropriate variables.
void ReadFiles(ifstream& infile, string SCoordsName, SCoords& start, SCoords& end, string mapName, int mapArray[10][10])
{
	//Read in file containing start and end poin of map.
	infile.open(SCoordsName);
	//Error check incase input file cannot be found.
	if (!infile)
	{
		cout << "ERROR: ";
		cout << "Can't open input file\n";
	}
	while (!infile.eof())
	{
		infile >> start.x >> start.y;
		infile >> end.x >> end.y;
	}
	infile.close();
	//Read in file containing terrain costs of map.
	infile.open(mapName);
	if (!infile)
	{
		cout << "ERROR: ";
		cout << "Can't open input file\n";
	}
	while (!infile.eof())
	{
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				infile >> mapArray[i][j];
				///open the file and put in the and then the new coordinates that we generate will relate to a positon in the array
			}							//and this will allow us to get the cost of that square.		
		}
	}
	infile.close();
}
コード例 #24
0
ファイル: tickets.cpp プロジェクト: AroSwift/CS1020
//
// get_file
// Open the file. If it exists and has content pass back input.
// Otherwise, exit the program with an appropriate error message.
//
void get_file( ifstream& input ) {
  // Read in file
  input.open(FILE_NAME);

  // When file could not be found
  if( input.fail() ) {
    cout << "Input file " << FILE_NAME << " does not exist. \n";
    exit(1);

  // When file is empty
  } else if( input.peek() == EOF ) {
    cout << "Input file " << FILE_NAME << " has no tickets to read. \n";
    exit(1);
  }
}
コード例 #25
0
int InputNumScores(ifstream& input)
{
  int numScores;
  string fileName = "c";
  cout << "What file will you be reading from, sir or madame?\n";
  cin >> fileName;
  input.open(fileName.c_str());
  if (input.fail())
    {
      cout << "File read error.\n";
      exit(1);
    }
  input >> numScores;
  return numScores;
}
コード例 #26
0
ファイル: FileHandler.cpp プロジェクト: thomx12/Tribute
std::vector<std::string> FileHandler::getHighscoresbyLevel(std::string level)
{	
	highscores.clear();
	
	scoreStream.open("Scores\\scores_level" + level + ".txt");	

	while(!scoreStream.eof())
	{		
		getline(scoreStream,s);	
		highscores.push_back(s);
	}	
	
	scoreStream.close();
	return highscores;
}
コード例 #27
0
//********************************************************************************************************************
//********************************************************************************************************************
int openfiles(ifstream& files, ofstream& outfile, ofstream& errorfile, string filename, int errorcheck) {
	cout << "Please tell me your file name.\n";
	cin >> filename;
	files.open(filename.c_str());
	outfile.open("Outputfile.txt");
	errorfile.open("Errorfile.txt");
	if (files.is_open()) {
		errorcheck=1;
	}
	else {
		cout << "Could not open file.  Please exit program.\n";
		errorcheck=0;
	}
	return errorcheck;
}
コード例 #28
0
ファイル: open_read.cpp プロジェクト: hsnajafabadi/rcade
bool _open_input( ifstream &ifs, const char *path, const char *extension )
// opens an input file stream
// returns true if successful, false otherwise
// extension will be used only if 'path' itself does not exist
//
// ifs: the file stream that will point to the input file
// path: the path and the name of the input file
// extension: the default extension of the input file. if the input file itself cannot be openned, this will be appended to the end of the input file name, and will be tried again
{
	char input[ MAX_STRING_LENGTH ];
	strcpy( input, path ); // copy the path to the input file name

	// first attempt
	ifs.open( input, ios::in );
	if( !ifs || !ifs.is_open() )
	// the first attempt was unsuccessful
	{
		// second attempt
		ifs.clear(); // clear the error flag

		cout << "WARNING: " << input << " was not found. ";
		strcat( input, extension ); // append the extension to the end of input file name
		cout << "Trying " << input << "..." << endl;
		
		ifs.open( input, ios::in );
		if( !ifs || !ifs.is_open() )
		// the second attempt also failed
		{
			cout << "ERROR: " << input << " was not found." << endl;

			return false;
		}
	}

	return true;
}
コード例 #29
0
ファイル: macroProcessor.cpp プロジェクト: moonblade/SP_LAB
int main(int argc, char const *argv[])
{
	// Open input and output files
	inFile.open("input");
	outFile.open("output");
	// Create an empty line
	Line line;
	// Loop till opcode is END, and process each line
	while((line=getLine()).opcode!="END")
		processLine(line);
	// Close the files, really important
	inFile.close();
	outFile.close();
	return 0;
}
コード例 #30
0
int main(int argc, char** argv)
{
  
  if(argc != 6 )
    {
      cout<<"\nMain function arguments incorrect! Exiting program!\n";
      cout<<"\nSample Usage: ./a.out treesfile k a freqpc outputfile \n  k = size of seed, a = number of contractions, freq = percentage criterion";
      cout<<endl;
      exit(0);
    }
      
  /*copy command line arguments*/
  strcpy(filename, argv[1]);
  k    = atoi(argv[2]);
  a    = atoi(argv[3]);
  freq = atoi(argv[4]);
  
  fin.open(filename);
  if(!fin)
    {
      cout<<"\nPlease check if the file is present. Error Opening Input File.";
      return 1;
    }

  fin.close();
  clock_t start = clock();
  compute_parameters();
  char* k_n_f_seeds_txt = argv[5];
  knfglobal = k_n_f_seeds_txt;
  //char dummy[10];
  //strcat(k_n_f_seeds_txt, argv[1]);
  //sprintf(dummy,"%d",k);
  //strcat(k_n_f_seeds_txt,dummy);
  //strcat(k_n_f_seeds_txt,"_");
  //sprintf(dummy,"%d",a);
  //strcat(k_n_f_seeds_txt,dummy);
  //strcat(k_n_f_seeds_txt,"_");
  //strcat(k_n_f_seeds_txt,"seeds.txt");
  cout<<"\n\nExtracting Seeds...";
  find_seeds();  
  clock_t end = clock();
  cout<<"\nDone!";
  cout<<"\n\nNumber of Seeds\t"<<seed_count;
  cout<<"\nSeeds file\t"<<k_n_f_seeds_txt;
  double seconds = (double)(end - start )/CLOCKS_PER_SEC;
  cout<<"\nTotal time taken "<<seconds<<" seconds\n";
  return 0;
}