|
I'm working on my assignment for school, which is to write a C++ program. This one's kinda hard, and I'm stuck, so I was wondering if there's anyone out there who could help me out.. I'd be very, very grateful if there's someone who can. I'm giving a short description of what the program has to be like.. If anyone understands it, could you just give me a hint of how I could do it? The first step of the program is as follows: - There is a coded file.. Something like this. From the first line I have to find the highest number, and then find the first two characters (letters) that come after it. So if the first line of the file is: abcD%44$trt112yyu77%55 kfkj-117 Hart5))-7yytat , then the two letters the program would have to find are Ha, since the highest number of this line is 117. Later on there are other things that I have to do, but this is the first step of what I have to do and that's where I'm stuck. I hope this made any sense. If there's anyone out there who could point me the right direction, I'd really appreciate that and I'd be forever grateful to you..
Last Edit: Oct 8, 2007 18:22:10 GMT by Shraddha
|
|
|
|
I don't know C++, this is pseudo-code in JavaScript. It's rather straight forward and my comments (they follow a // ) should explain the concept. Also, I use RegExp in this concept. CrAzY_J says C++ supports RegExp, though he doesn't know how to use it. I can't help with that unfortunately.
// Get a line from the file to check. var stringToCheck = getLineFromFile();
// Store the current highest number in this variable var hiNum = -1; // Start negative so we always have a higher
// Store the current value in this variable var holder = "";
// While we find a number in the string, let's grab it and the next two items. while(stringToCheck.match(/(\d+)(..)/)){ if(RegExp.$1-0 > hiNum){ // -0 makes it a number. We're also comparing the two current values. // Update the information hiNum = RegExp.$1; holder = RegExp.$2; }
// Remove the characters stringToCheck = stringToCheck.replace(/\d+../,""); }
|
|
|
|