C++ :: Finding Maximum Value In A Map
Jul 26, 2014
Suppose that a map is defined thus: map<sttring, int> mymap;
I wanna find k maximum values. Is there a way to find the maximum value in an efficient manner? Or else, How can I sort them and then find the k first elements?
View 1 Replies
ADVERTISEMENT
Nov 12, 2014
This is part of my main code that is giving me compiler issues.
//Find max value
max = max_element(vecTemperature.begin(), vecTemperature.end());
I keep getting an error saying "[Error] cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in assignment"
View 2 Replies
View Related
May 8, 2014
What is the syntax to find the maximum of a function over the interval a≤x≤b starting at a with a step size of Δx ?
View 1 Replies
View Related
Oct 29, 2014
A function finds approximate maximum or minimum point of a second degree polynomial function (the point where the derivation will equal to zero ). The input polynomial function will be in the following format:
x2 + bx + c = 0 .
Your C function should take a , b and c as input parameters. Your C function also should take the srch_starting_point and stp_sze from the user. Finally, print the resulting maximum or minimum point (m_x, m_y) and step count (n_step) in your function.
For example, if the input is (a, b, c, srch_starting_point, stp_sze );
1 1 1 -3 1
Output similar to;
Maximum point results ( m_x, m_y, n_step )
-1 1 2
i can find the minimum point at first(Using derivation). After choosing starting point, staating point gets lower step size by step size. I can compare numbers to the minimum number. Afterwards, to find m_y i put m_x in the function. Finally, I put a counter to count steps.
View 4 Replies
View Related
Jan 22, 2013
I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!
#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;
[Code] ....
View 2 Replies
View Related
Sep 20, 2013
I have this code that determines the amount of people that can fit on some trains in different train combination scenarios. Here is the code:
#include<stdio.h>
#include<stdlib.h>
int main(void) {
int total_track, max_train_length, num_people, num_trains, tl;
printf("What is the total length of track, in feet?
[Code] ....
I need to now "pick the winner," or the highest value for num_people computed. How would I go about this and why?
View 6 Replies
View Related
May 23, 2013
Is there a maximum capacity for stdin ?
View 2 Replies
View Related
Mar 12, 2014
I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.
Code:
private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];
[Code] .....
I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this
Code:
int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)
[Code] .....
It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually?
View 8 Replies
View Related
Jan 4, 2015
I wrote a program to find the minimum and the maximum values from a vector. It works fine. What I'm trying to do is show the positions of said values and it's not working quite right. When I insert 4 elements: 2 0 1 3 it says:
"The min and max are 0 and 3
The position of the min is: 01
The position of the max is: 03"
What am I doing wrong? Here is the code:
Code:
#include <stdio.h>
#include <conio.h>
int main() {
int A[10], i, j, n, min, max, C[10], k=0, D[10], l=0;
printf("Insert no. of elements in vector A
[code]....
View 6 Replies
View Related
Oct 29, 2014
Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.
In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
[Code].....
View 10 Replies
View Related
Sep 10, 2013
I am working on a couple C++ projectsfor my class. On one of my projects I get this error "identifier not found" for maximumValue. here is the code that I have done. I have got almost all the code from my text book..
// Three numbers.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
// demonstrate maximum int value
int int1, int2, int3;
[Code] .....
View 5 Replies
View Related
Dec 9, 2013
I have a vector of vectors declared as:
vector<vector<int>> v;
My program works fine with a small number of insertions to v. However, with a huge number of insertions my program stops working without telling me the reason... I guess that vectors might not grow after a certain size (im not sure)
1. What is the maximum size that a vector of vectors can grow?
2. I'm using Microsoft visual studio 2012, Is their anything I can do with the settings to increase the size of my vector? something beyond 1000000 rows?
View 6 Replies
View Related
Feb 5, 2014
My program enters the size of the vector from the user and then creates a vector of vectors (lets say SIZE1). In addition the user enters the number of vector of vectors he needs (lets say SIZE2) as follows:
class Vectors {
// member functions goes here
private
vector<vector<int>> vectors;
vector<int>::iterator it;
[Code] .....
With a few calculations and insertions to my vector (vector of vectors)... the program works fine and gives me the results...
However, with huge calculations and insertions the program stops working and gives me this message
"Unhandled exception at at 0x770DC41F in Test.exe: Microsoft C++ exception:std:bad_alloc at memory location 0x001CEADC"
Thus, it seems that the vector reached it's maximum size... I tried to use reserve() but did not work
I read that "By default, when you run a 64-bit managed application on a 64-bit Windows operating system, you can create an object of no more than 2 gigabytes (GB). However, in the .NET Framework 4.5, you can increase this limit"
What do you think would be the best option for me to do (note my program is very long and complex)(I'm currently using Microsoft Visual Studio 2012 32Win application):
1. convert my program to the .NET Framework (C++)
2. convert my program to C# in case c#
3. do any settings on my computer (my workstation has a 3.6GHZ xion processor with 32RAM
4. convert to another version of C++ that does not have any restriction on the size of the array (if available)
Please note that I never worked neither with the .NET framework nor C#
View 3 Replies
View Related
Oct 17, 2014
The problem says that i have a number n > 0 and the program should determinate the number between 2 and N who has the maximum divisor sum (1 and N wont count as divisor). If i have more numbers with maximum divisor sum, should wrote only first number. Exemple: for N = 100 , will show 96 bcoz he has the maximum divisor sum, which is 155. For the start i tried to show only the maximum divisor sum, not the number who has the maximum divisor sum with this code:
#include<stdio.h>
int main() {
int n,s=0,i,m;
printf("Please introduce the number N > 0:");
scanf("%d", &n);
i = 2;
[Code] .....
And it shows me 116, but the correct results is 155. Which is the problem ?
View 4 Replies
View Related
Jan 25, 2014
I'm new to C++ and I'm trying to solve the question but there is just something wrong somewhere.
#include <iostream>
using namespace std;
int main() {
int largest;
int a;
int b;
int c;
cout<< "Enter first value";
[Code] ....
View 1 Replies
View Related
Apr 21, 2013
I use Visual C++ to write a native C++ application. How to know the maximum memory it will use during its execution?
View 5 Replies
View Related
Aug 2, 2014
I was given some practice problems in my programming class, to prepare for the final and I don't quite understand what this one is asking for exactly:
Write the remainder of the program to find the maximum value for the middle row of the array data. Print the max after finding it. Your code should work for any 2D array of ints with three rows and four columns, so don't hard-code your program to these specific values.
Code:
#include <stdio.h>
int main(void)
{
int data[][4] = {{ 5, 8, 7, 2},
{ 3, 10, 1, 9},
{ 6, 12, 5, 0}};
View 8 Replies
View Related
Jul 28, 2014
I have problem with finding the maximum value in a column. This is my code
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
fp = fopen ("C:
ocket1.txt", "r");
float time, altitude, velocity, acceleration, amax, bmax;
[Code] ....
The first loop will print out all of numbers in the velocity column. The second while loop is looking for the maximum value in that column. It is supposed to print out the max velocity in the end of the second loop. However, when I build and run the program, it's crashed. I run debugger and received "Segmentation fault" error. When I eliminate the second loop, it run just fine I use Code::Block for text editor.
View 8 Replies
View Related
Sep 29, 2013
Program that reads 10 students marks and display the average, the maximum and the minimum marks.
Code] ....
#include <Stdio.h>
main(){
// Local Declarations
int marks[10];
int i; /*loop counter */
int avg;
int sum = 0;
[Code] ....
In this program i am able to get Average Marks and Minimum Marks But i am not able to get the Maximum Marks Output correct.
View 6 Replies
View Related
Feb 3, 2014
How will you code a program that displays the maximum value in a two dimensional array of integers. the program will ask the user to input the 4x5 array?
i know how to code it. but i dont know what to do to find the maximum value. :( how to find the maximum?
View 4 Replies
View Related
May 22, 2014
i have tried like that int arr[1000000] to initialize but it crashed my programm.but if i do int arr[100000] it works fine..why is that and what is the maximum range of integer array initialization??
View 5 Replies
View Related
Aug 12, 2014
I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case
1. Find the maximum value of the array
2. Find the sum of the first and last element of the array
3. Swap the adjacent pairs of arrays
4. Display the values in array
5. Quit
Please enter choice:
but when i try running the program i did i keep having the break or continue pop up ....
#include <iostream>
using namespace std;
int main() {
int choice;
int number[10] = {2,3,4,5,6,9,10,11,12,99};
[Code] .....
View 6 Replies
View Related
Nov 17, 2014
I have come across a problem lately. You are given a set of n sets with m variables.. for instance {a,b,c,d}, {b,c,d}, {b,c}, {c,e,f}, {e,f}. And you want to eliminate elements from these sets with the restriction that you can only eliminate one item from each set and each item can only be eliminated from one set (i.e. if you've eliminated b from set {a,b,c,d}, then you cannot eliminate it from {b,c,d}). The problem is writing an algorithm which determines the maximum number of elements you can eliminate. And I'm hopelessly stuck... of course, you could backtrack it and determine this number but I feel it could be done more efficiently..
View 2 Replies
View Related
Sep 10, 2013
Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.
Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element.
Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B .
View 4 Replies
View Related
Oct 7, 2014
I am new at c++ and I am trying to write a code to determine the maximum deflection at the end of a cantilevered beam. I am given the formula : deflection= (4 W L^3)/(E B H^3) where W is the load weight, L is the beams length, E is the modulus of elasticity, B is the beams base, and H is the beams height.
// Included Header Files
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cstdio>
[code]....
View 2 Replies
View Related
Dec 6, 2013
I need to write a program that not only calculates the minimum and maximum, but also calculates the average and the difference between the largest and the smallest.
Here's the code:
#include <iostream.h>
#include <conio.h>
#inlcude <math.h>
#include <windows.h>
[Code].....
I know the problem is the "sdt::cin" but I don't know what else to do
View 1 Replies
View Related