C++ :: Selection Of Interesting Point From Long List
Mar 29, 2013
I have some codes which are not efficient enough to get the answer faster.
Q: Tom is looking for a car with high miles per gallon and high horse power.For example:P1--Toyota with MPG=51,HP=134, the P2--Honda with MPG=40,HP=110, P3--Ford Fusion with MPG=41,HP=191,P4--Nissan with MPG=35,HP=195,P5--Volkswagen with MPG=30,HP=140
Since,p2 is worse than p1(in terms of MPG,HP) and p5 worse than p4(MPG,HP), thus they are cancelled. The leftover 3 cars are considered interesting cars.Tom wish to find all interesting cars from the list but there's too many of them. Thus write a program to find this list as fast as possible.(C++)
int SimpleAlgo2 (int &n, int &d, vector< vector<float> > &point) {
vector<bool> isBest(n+10, true);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
// We will check if point[i] is strictly worse than point[j]
// no need to check if we already know that point[i] is not the best
if (isBest[i]) {
[Code] ....
View 3 Replies
ADVERTISEMENT
Jun 2, 2014
How to put together this assignment. Here is the assignment:
The ABC Shipping Company charges the Rates listed in the following table:
Weight of the package (in kilograms) Shipping rate per mile in California Shipping rate per mile other states
2 kg or less $2.0 $2.5
Over2 kg but not more than 6 kg $3.0 $3.5
Over 6 Kg but not more than 10 kg $3.5 $4.0
Over 10 Kg but not more than 30 Kg $4.0 $4.5
Over 30 kg $5.0 $5.5
Create an application that contains two radio buttons to select California or other states, a listbox for the user to select the package’s weight class, a textbox to enter the distance it is to be shipped, and a button to calculate and display the charges on a label control when it is clicked.
Input validation: Do not accept distances of less than 5 miles or more than 3000 miles
This is what I have so far. I don't know how to set up the listbox option for non california or how to set up a formula.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
[Code] ....
View 3 Replies
View Related
Apr 1, 2015
I have a long long int k=0x0000888804eaad0e
And i need the reverse of this (nibble wise) in other long long int variable.
That is i want the result to be = q=0x0000e0daae408888;
Or the result also can be like this = q=0xe0daae4088880000;
How to accomplish the above?
View 4 Replies
View Related
Jul 23, 2014
I thought I'd display my fun use of the new C++11 auto keyword to create a compile time foreach. It only works for STL collections, or anything that implements the STL collection iterator methods begin(), end() that return a STL iterator.
// Standard Template Library foreach
// element = iterator name
// collection = STL data collection variable
#define stl_foreach(element, collection)
for(auto element = collection.begin(), __end__ = collection.end();
element != __end__; element++)
}
[code]....
View 2 Replies
View Related
Feb 9, 2013
I'm trying to make a selection process using roulette wheel selection. To do this I created two matrix, one random probabilities and one increasing probabilities. The idea is to choose a number according to the random probabilities. Here is the code I've written.
#include <iostream>
#include <conio.h>
#include <cstdlib>
using namespace std;
int main (){
float select [5], prob [10], mat [5];
int c, r, z;
cout.precision (2);
cout << "Random Number:" << endl;
[Code]...
The result I got is as follows:
Random Number:
0.0013 0.56 0.19 0.81 0.59
Increasing Probabilities:
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Selected Column:
0
5
6
8
9
The evaluation doesnt seem to start from c=0 again. The selected column should be 0, 5, 1, 8, 5.
View 6 Replies
View Related
Jun 26, 2013
I have one code that use MPI broadcast and I want to change it into Asynchronous Point to Point communication. I am newbie in Parallel programming. Looking for implementation of one simple same program in broadcast and P2P ?
View 6 Replies
View Related
Dec 4, 2013
I've written a code that request for a password and its suppose to look like this.
Sample Output (inputs in bold)
Please enter a password: pass6
Passwords must be at least 7 characters long
Please enter a password: TarrantNW
Passwords must include a digit or dollar sign (0-9, $)
Please enter a password: Tccd-03
But when I run the program it stops at "Passwords must be at least 7 characters long" and the box closes and where I should put the loop=
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
const int SIZE = 7;
char password[SIZE + 1];
[code]....
View 3 Replies
View Related
Aug 15, 2013
I want to write encryption algorithm.first af all I need to define variable( binary input ) that it is 256 bit but I dont know what should I use...then I want to XOR this to variable ( a & b ) ( each of them is 256 bit)
View 6 Replies
View Related
May 9, 2014
I'm not understanding why the string provided for initialization is too long?
Code:
int main()
{
char array[1] = "A";
return 0;
}
View 6 Replies
View Related
Feb 21, 2013
Without lossing information?
View 14 Replies
View Related
Mar 11, 2013
I have a problem with converting a C++ string into a long double. In order to do this, I used the function strtold, but the result I get is only the integral part, that is: if for example the input string is 12.476, I only get 12 as the converted long double value. This happens with atof too.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
string test = "12.345";
long double test_longd = strtold(test.c_str(),NULL);
[Code] .....
View 3 Replies
View Related
Jan 4, 2013
Working on a Project Euler problem and the question asks for the largest prime number that is a factor of 600851475143. As you can see, this is significantly larger than the maximum of a long data type, which maxes out at 2147483647.
I'm running on Windows 32, so int64 is not a valid option for me. It seems like I'll likely have to use a different language to solve this problem.
View 4 Replies
View Related
Jun 15, 2014
So I have problem with my code, I'm trying to convert string to long and then string to double, but I get this when I compile it:
terminating with uncaught exception of type std::invalid_argument: stod: no conversion
I was thinking if there is a way to do this without using (stol) or (stod)
Market::Market(string filename)
{
string line, word, date, stockprice;
long realdate;
[Code].....
View 14 Replies
View Related
May 9, 2014
I am trying to highlight integers in a textbox.
The problem, is that I dont know how to make Regex get Integers no matter what (e.g. even if an =, >,<,>=,<= sign is in front or anything) unless it is encased in a string e.g. "'s or whatever.
My current code does this:
I do not want the numbers to be highlighted if they are in a string.
View 6 Replies
View Related
Nov 11, 2014
My code:
#include<cstdio>
#include<iostream>
using namespace std;
main() {
long double j;
scanf("%Lf", &j);
cout<< j;
return 0;
}
If I give any number as input, the output is always 0. why? where's the problem ? p
View 6 Replies
View Related
Apr 8, 2013
How can i display words form a long sentence.
example :(lets assume that if u find two spaces that is word)
INPUT: the Indian school boys are very good compare to other countries.
OUTPUT: the Indian
school boys
are
very
good
compare to
other countries
I am solving these way but it takes only one space to divide a word.
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
int main() {
std::vector <std::string> words;
[code] .....
View 1 Replies
View Related
Feb 8, 2014
I'm making a program that would run 24/7 and that could be run on multiple computers that are all running Windows (the program would be in the startup folder of the computer).
So I'm searching for 2 functions, one that would check if the program has been already launched on this computer and another one that would do a save every 24 hours. but for the second one I don't know what I should do because I think that a loop with sleep() would take too much power for the cpu
View 7 Replies
View Related
May 4, 2014
I am trying to print out 2^1000. I am not entirely sure on how to implement the constructor. I currently just have x.push_back(n) as my constructors implementation. For the function double(), it is suppose print 2^10 as 1024 and the function addDigits() should print 2^10 as 7. Am I suppose to create a Long object with 2 as a parameter and then use double() to double it 10 times?
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
class Long {
[Code] .....
View 6 Replies
View Related
Aug 1, 2012
my array contains elements of integer type
how can i convert my array to long array
View 1 Replies
View Related
Nov 7, 2012
I have written a windows service which run continuously on a server. Interval time is 9 sec. On timer1_interval i am fecthing record from database and sending it to user. And changing its record status.
this service stop fetching records after running 4 to 5 days. We need to restart the service. there is no GUI involve in this code
View 1 Replies
View Related
Jan 10, 2014
I have to write a program, that multplicates very large numbers (out of range of long int). It's said that i need to use arrays and read the numbers as strings. My problem is to end function called "mnoz:, because i don't know how to sum the multiplicated values of arrays a and b.
Code:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include "winbgi2.h"
#include<string.h>
#define roz 10000
char lan(char a[])
[Code] ......
View 1 Replies
View Related
Feb 7, 2014
I am making a function that will return a pointer to a long long variable. For example, I have the next variable prototype: Code: long long funcName(long long x, int s); I want to change the return value, and the first parameter to pointers to long long.
View 4 Replies
View Related
Apr 25, 2013
I'm currently working on a simulation of the motion of magnets on a rod. As part of it, there are arrays of the properties of the magnets:
long double *accelerations; // These will later be dynamically allocated depending on the number
long double *velocities; // of magnets
long double *positions;
However, when I go to compile this, the compiler gives me these error for the pointers:
error: two or more data types in declaration of 'accelerations'
error: two or more data types in declaration of 'velocities'
error: two or more data types in declaration of 'positions'
Apparently, the compiler isn't recognising long double* as a type and is instead reading is as the two types long and double*.
My compiler is MinGW 4.4.3
View 4 Replies
View Related
Aug 3, 2014
So I have been given and as part of the solution I need to count the number of digits in a long long variable. To do this I use a while loop, but it is behaving strangely. Here is the code.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main (void) {
printf("What is the card number?");
long long card = GetLongLong();
if(card <= 0)
[Code] .....
When I execute the program it asked for the number, but then nothing happens. Of course, my first instinct was that the program was caught in an infinite loop somehow, but could not figure out how. I commented out the while loop and the program completed (albeit returning the incorrect value), so I was further convinced that there was an infinite loop that I was not seeing. I ran the program throug gdb. Strangely, the program did not loop infinitely, instead it got to line 16 [while(card1 > 0] and then just stopped, it was not executing the next line of code at all.
View 6 Replies
View Related
Jun 11, 2014
I am trying to send the maximum long value through function call, but i didn't print proper value..
[
#include <stdio.h>
long long floatToInteger_old(float value){
printf("float val : %e",value);
}
int main(){
float value = 340168346567;
long long finalhexVal = floatToInteger_old(value);
return 0;}
]
my actual output is 340168346567, but it is printing 3.401683e+011 or 340168343552.000000.
how can print exact value what i am sending.
View 7 Replies
View Related
Oct 29, 2012
Here is the code:
int unsigned long a,b;
scanf("%lu",&a);
scanf("%lu",&b);
printf("%lu",a*b);
suppose we input a very large number on a and b (no more than 1000 digit)
like a = 1234567890123456789012345678901234567890
and b = 9876543210987654321098765432109876543210
it outputs 1, why is it?
It is probably the answer is too big, is there any way to show a*b?
View 1 Replies
View Related