Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
C++ maximum sum in a series of #s
Name: magic010 Date: February 24, 2004 at 05:54:48 Pacific OS: windows 98 CPU/Ram: ?
Comment:
I need help with this problem: Given a series of numbers separated by spaces, find the maximum sum from some consecutive number subset of the numbers. For ex. if we give you the set of numbers: 10 12 -3 -4 12 -13 3 -35 7 8 9 12 -2 -3 15 -6 -2. The maximum sum from a consecutive subset of numbers is 7+8+9+12-2-3+15=46. You should accept as input the set of numbers and produce as output the max sum from that set of numbers.
All I know how to do is input the numbers. I input them in a string, however, I do not know how to work with numbers in a string. Any help is greatly appretiated. Thanks
Name: Don Arnett Date: February 24, 2004 at 07:04:34 Pacific
Reply:
Why not input them as numbers using scanf? This code will input the entire line (or file) as long as it's only numbers.
int arry[100]; int i=0;
for (i=0; scanf("%d",&arry[i]) == 1; ++i) continue;
After the loop, i will tell you how many numbers are in the array. You should probably add a check that you don't input more than the array will hold.
If you want/have to input as strings, use atoi() to convert a string to an int.
int i; char numString[100] = "123";
i = atoi(numString);
0
Response Number 2
Name: magic010 Date: February 25, 2004 at 06:25:10 Pacific
Reply:
Thanks for the help, I'm trying it out today. I'll post again if I need more help. Thanks again
0
Response Number 3
Name: magic010 Date: February 25, 2004 at 06:55:32 Pacific
Reply:
Hey, I don't have any experience with scanf. I used the code you posted but then I don't know how to work with the input or get any output. I'm actually in a hs class, and our teacher gave us this problem to prepare for a contest. The problem is, he doesn't even know how to complete the problem. So we've been trying to research a little bit, but most of the code like scanf just looks foreign. So if you could post something a little more specific or maybe some example code, we would appreciate it. Thanks again
Summary: Hello, I am trying to insert the filename (minus the extension) in front of every line in a series of TXT files. I have put together code to make the change in a single txt file, but am lost as how t...
Summary: I am trying to make a program in C++ to read in a bunch of numbers from a file "frames.txt" like shown here: Frame: 00 FE 08 08 00 60 00 23 A1 23 0E 9C FE 03 5B 6D 77 64 57 65 63 64 61 63 63 CE FE FF...
Summary: Hi there, it is homeworkthe calculation!!! im trying to use functions (not homework) i would like do it without arrays (not homework) I need a little bit help with the error message error C2448: '<...