problem solved but is not accepted.

This is a discussion on problem solved but is not accepted. within the C++ Programming forums, part of the General Programming Boards category; Hi there. I'm trying to solve this problem : http://acm.uva.es/p/v111/11172.html So i wrote this: Code: #include <fstream> #include <iostream> using ...

  1. #1
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71

    Question problem solved but is not accepted.

    Hi there. I'm trying to solve this problem :
    http://acm.uva.es/p/v111/11172.html
    So i wrote this:
    Code:
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int pairs;
    	int i, first, second;
    	char pFirst[80], pSecond[80];
    	char buffer[80];
        char szFile[80];
    
    	cout << "Give the name of the file : " << endl;
    	cin >> szFile;
    	ifstream my_file(szFile);
        if(!my_file) {cerr<<"No such file"<<endl;getchar();exit(1);}
            my_file.getline(buffer,80);
    
            pairs=atoi(buffer);
    
    	for(i=0;i<pairs;i++)
    	{
    		my_file.getline(pFirst,80,' ');
    		my_file.getline(pSecond,80);
    
    		first = atoi(pFirst);
    		second = atoi(pSecond);
    
    		if(first>second) cout << '>' << endl;
    		else if(first<second) cout << '<' << endl;
    		else cout << '=' << endl;
    	}
        
        cin.get();
        return 0;
    }
    My code works fine (shows the correct results) both in VS 2005 and dev-C++. But, when I submited it to the uva, it was not accepted( had runtime or compilation error)

    The weird thing about this problem is that although it needs to load a file as input,
    (in uva) I am asked to upload only my code....

    It's the first time I upload a code there and I'm a bit fuzzed. Can you please help me?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Well the final cin.get(); is inappropriate for a non-interactive test.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    At the top of the page it specifies the input is coming from the standard input. Wouldn't that mean that the file is piped to your resulting executable? That is, interactive input for the name of the input file is not something you'd want to do?

    [edit]That is, the output of your code might be this:
    D:\scratch>cppapp < file.txt
    Give the name of the file :
    No such file
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71
    Quote Originally Posted by Dave_Sinkula View Post
    Wouldn't that mean that the file is piped to your resulting executable? That is, interactive input for the name of the input file is not something you'd want to do?
    OK, if I understand right you mean , sth like this...

    Code:
    int main(int argc, char** argv);
    {
    ....
    ifstream my_file(argv[1]);
    ....
    }

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Like the text on the question page says
    Quote Originally Posted by question
    Problem H
    Relational Operators
    Input: Standard Input
    Output: Standard Output
    It means the online test is going to do this
    gcc yourcode.c
    ./a.out < testfile > testresult
    diff testresult expectedresult


    If the result of the diff command is no differences, you pass, otherwise you fail.

    So everything you read should be from cin, and all output goes to cout.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A confusing problem with my linked list
    By edd1986 in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 09:33 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21