Whats wrong with this?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1257 Views - Last Post: 07 December 2010 - 12:54 PM Rate Topic: -----

#16 Kohana  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 56
  • Joined: 09-January 10

Re: Whats wrong with this?

Posted 06 December 2010 - 09:40 PM

#include<iostream>
#include<vector>
#include<fstream>
#include<string>

int main(int argc, char **argv){
	
	// Declarations
	std::string str;
	std::vector<std::string> myVector;
	std::string inputString=argv[1];

	// Open file and stores words in a vector
	std::ifstream myFile(argv[2]);


	while (myFile.good()){
		std::getline(myFile,str);
		myVector.push_back(str);
	}
	



	// Check if word is in the Vector and return count as line number
	// if word is not in the list the bool will remain false.
	// The bool is checked after the loop
	
	bool wordInList=false;
	int lineCount=1;															// Start at line one								
	for(int i=0;i<myVector.size();i++){			
		if(inputString == myVector[i]){
			std::cout << lineCount << std::endl;
			wordInList=true;
		}
	lineCount++;
	}

	if(wordInList == false){
		std::cout << 0 << std::endl;
	}

}





Done it. The my file.open line was the error, upload successful.

Haha thanks mate
XxX

Scrap that, it failed 2 of the 5 tests,


Puzzle: Fast grep utility
Status: Fail Date: Mon, 12/06/2010 - 21:33
Details: 2 tests have failed

Test status/name: Pass/Simple test
Description: Testing the rest of the example
Max CPU: 1.00 seconds Max Memory: 100.00MB
Sol CPU: 0.00 seconds Sol Memory: 0.00MB

Test status/name: Fail/Big file, test #1
Description: A word near the beginning
Max CPU: 1.00 seconds Max Memory: 100.00MB
Sol CPU: 0.02 seconds Sol Memory: 0.00MB
Details: Your submission didn't give a correct answer on this test. Please verify your code.

Test status/name: Fail/Big file, test #2
Description: A word near the end
Max CPU: 1.00 seconds Max Memory: 100.00MB
Sol CPU: 0.02 seconds Sol Memory: 0.00MB
Details: Your submission didn't give a correct answer on this test. Please verify your code.

Test status/name: Pass/Big file, test #3
Description: A missing word due to case
Max CPU: 1.00 seconds Max Memory: 100.00MB
Sol CPU: 0.03 seconds Sol Memory: 0.00MB

Test status/name: Pass/Big file, test #4
Description: A missing word
Max CPU: 1.00 seconds Max Memory: 100.00MB
Sol CPU: 0.04 seconds Sol Memory: 0.00MB
Was This Post Helpful? 0
  • +
  • -

#17 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Whats wrong with this?

Posted 06 December 2010 - 09:41 PM

When you're posting it, are you selecting "C++" from the drop-down menu?

You're obviously doing something wrong, because I just took your code from post #4, commented out lines 34-36, pasted it onto their page (replacing all of their skeleton code), and clicked "verify" and it worked.
Was This Post Helpful? 1
  • +
  • -

#18 Kohana  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 56
  • Joined: 09-January 10

Re: Whats wrong with this?

Posted 06 December 2010 - 09:48 PM

View Postr.stiltskin, on 06 December 2010 - 08:41 PM, said:

When you're posting it, are you selecting "C++" from the drop-down menu?

You're obviously doing something wrong, because I just took your code from post #4, commented out lines 34-36, pasted it onto their page (replacing all of their skeleton code), and clicked "verify" and it worked.


Yeah mate and varify works with the latest code post but then I fail 2 of the 5 tests. It's an improvement I guess
Was This Post Helpful? 0
  • +
  • -

#19 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Whats wrong with this?

Posted 07 December 2010 - 12:06 PM

OK, so I tried submitting a solution and the exact thing happened -- it passed 'verify' but then failed the same 2 tests as yours. Then I realized what the problem was & submitted another which passed all tests. The problem is that we were comparing the search string to entire strings (ENTIRE LINES) in the test file. Instead, the program also has to find the search string if it is a sub-string of one of the strings in the test file. In other words, using your myFile.txt, if you give it "TE" as the search word, it should find that on line 10 of the test file. Their instructions don't make that clear, but it's apparent from the results.
Was This Post Helpful? 0
  • +
  • -

#20 Kohana  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 56
  • Joined: 09-January 10

Re: Whats wrong with this?

Posted 07 December 2010 - 12:13 PM

View Postr.stiltskin, on 07 December 2010 - 11:06 AM, said:

OK, so I tried submitting a solution and the exact thing happened -- it passed 'verify' but then failed the same 2 tests as yours. Then I realized what the problem was & submitted another which passed all tests. The problem is that we were comparing the search string to entire strings (ENTIRE LINES) in the test file. Instead, the program also has to find the search string if it is a sub-string of one of the strings in the test file. In other words, using your myFile.txt, if you give it "TE" as the search word, it should find that on line 10 of the test file. Their instructions don't make that clear, but it's apparent from the results.



Haha sneaky that. So include a substring search then.....that is sneaky. This is why us programmers get frustrated with people. Ask us what you want, we ain't psychic, am i right? lol
Was This Post Helpful? 0
  • +
  • -

#21 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Whats wrong with this?

Posted 07 December 2010 - 12:54 PM

Right -- shouldn't have to figure out the assignment by trial and error.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2