C++ :: Sorting From Match Data
May 13, 2014
say I have person 1 to person 1024
Let's say
I want to sort them from smartest to dumbest
I have very few data say
person 1 is smarter than person 23 and so on
There are many missing data
say I don't know if person 30 is smarter or dumber than person 50
How to sort this kind of array ?
I definitely know it can't be sorted but how can I sort this as best as possible.
View 4 Replies
ADVERTISEMENT
Aug 1, 2013
I've got two columns of data.
Code:
int a[6]={1,3,5,8,10,12};
int b[3]={3,5,9};
int c[6]={0}; if a is equal to ANY of the data in b, then c= a*2
if a isn't equal to any of the data in b, then c=a.
Here is the answer I want
Code:
c[6]={1,6,10,8,10,12}
I tried using two for loop, but it isn't correct.....
Code:
int a[6]={1,3,5,8,10,12};
int b[3]={3,5,9};
int c[6]={0};
for(int i=0;i<6;++i){
[Code] ....
View 3 Replies
View Related
Feb 4, 2014
How will you factor out data with different values to match to another value.
For example:
value A=100
value B=50,10,20,5,15,20,30
How will you construct a logic that the values on value B will have an equal value as value A.
100 = 50+20+10+20 or 100 = 50+30+20 and so on and so forth.
I am stuck.
View 2 Replies
View Related
Feb 21, 2013
My program compiles fine and doesn't have any errors so I am confused as to what the issue might be.
I have a int, which is determined by the user via cin.
I have a char, which is a random word generated from an input file.
1. I want the program to display "The word you entered does match..." if the word entered by the user is the same as the random word.
2. I want the program to display "The word you entered does not match..." if the word entered by the user is not the same as the random word.
The code I'm using for number one is
if (char == "int") cout << "does match..."
The code I'm using for number two is
else if (char != "int") cout << "does not match..."
Basically the programs only outputs "does not match" whether or not it really matches. Even if it matches, it outputs does not match.
Is something wrong with my code?
View 7 Replies
View Related
Feb 4, 2013
#include <iostream>
using namespace std;
class CD {
public:
static const int num = 100;
char publisher[num], title[num], location[num];
[Code] .....
View 1 Replies
View Related
Feb 11, 2013
Code:
typedef struct {
name_t name;
float beta[beta_num];
} gene_t;
[Code] ....
Is gene an array of address ? How come the compare function doesn't work ?
View 1 Replies
View Related
Apr 1, 2014
I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,
010000001110000000
there are 18 bits, 1 means a feature is present, 0 means the feature is absent.
Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.
The following data is ordered like I need it to be.
Code:
// block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical)
011000000001100000
011000000001100000
011000000001100000
011000000001100000
[Code] .....
This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.
This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.
Is there a standard method for this kind of pattern recognition?
View 14 Replies
View Related
Oct 24, 2013
I am having problems sorting data... I don't know to to go about it here is my code:
<code>
#include <iostream>
#include <string>
using namespace std;
int main () {
int i;
struct person
[Code] ....
i want to sort it out so that it can output names and ages in ascending order.
View 2 Replies
View Related
Nov 20, 2014
I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.
To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):
// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;
The two example functions I want to use are defined in that struct ("Data"):
// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}
The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:
// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}
The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);
the error becomes: "expression must have a (pointer-to-)function type."
The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:
// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);
This bit shows no errors by itself. So, my questions:
a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.
b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing
// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object
but that doesn't work ("a pointer to a bound function may only be used to call the function").
View 4 Replies
View Related
Dec 4, 2014
In the code below there is some error, I think it is related with functions. It compiles properly but then it outputs only : "humanslife8.90145e+032"
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;
void userInput(float HumanNumber, float SkeletonNumber, float AllHumanslife, float AllSkeltonslife, float SkeletonHealth, float HumanHealth);
void HumansTurn(int turn, float HumanAttack, float AllSkeletonslife, float HumanNumber, float HumanDamage, float SkeletonHealth, float SkeletonNumber);
[code].....
View 3 Replies
View Related
Feb 22, 2013
and see if the first three match a list then read in three more behind those that were left and perform a similar test on them and keep going?
View 8 Replies
View Related
Apr 18, 2013
I am trying to get the position of the matches of "Un" in string "Unseen University" in c++ code using STL regex. How can I do this.
i.e. I have following:
std::vector<std::cmatch*>* matches = new std::vector<std::cmatch*>*;
intMyReturnVal = regex("Unseen University", "Un", matches);
I can access a match by
matches->at(i)
and get an Iterator to the beginning of the match by
matches->at(i)->begin()
How can I get the relative position of the match within the entire target string (i.e. "Unseen University", where, in this case, the positions should be 0 and 7)??
View 1 Replies
View Related
Apr 17, 2013
I am using the (fairly) new STL implementation, which I just became aware of, of regexes. Seems to be an implementation of boost::regex Anyway, I have code, which I would like to use to get ALL matches within a string.
My String is: "Unseen University - Ankh-Morpork"
My regex is (simply): "Un" ;)
using code:
const char *reg_esp = "Un";
std::regex rgx(reg_esp);
std::cmatch matches;
const char *target = "Unseen University - Ankh-Morpork";
[Code] .....
gives output:
"Un" (one line only). How do I get this to match ALL instances of "Un" (i.e. that the output is "UnUn", i.e Un two times)?
View 2 Replies
View Related
Aug 2, 2013
I have a input record like
acct|N|Y|N|N|rose@gmail.com
Now I need to create a logic to append a code to the end of the file using the following matrix rules.
00NNNN
01NNNY
02NNYN
03NNYY
04NYNN
05NYNY
06NYYN
07NYYY
[code].....
In the above example these four flags are "N|Y|N|N", so I need to append the matching code at the end of file "04".
desired output :
acct|N|Y|N|N|rose@gmail.com|04|
as it matches code '04':
04NYNN
View 5 Replies
View Related
Oct 29, 2014
This program is supposed to compare 2 strings and print out a 1 if the characters match and a 0 if they dont. It compiles but doesnt give me the correct output.
Code:
#include <stdio.h>
#include <string.h>
void func();
int main () {
func();
return 0;
[Code] ....
View 11 Replies
View Related
Nov 25, 2013
I am trying to correlate the student's highest score with that student's ID. The old code is in blue and the new code is in green which includes a sort. The particular information in question is in red.
Ide1
Code:
#include <stdio.h>
int main(void) {
/*Set up two arrays to include up to 50 elements each.*/
int st_numval_id[50] = {0}, st_val_tstscr[50]= {0}, i = 0, j = 0, temp;
[Code] .....
Enter the student's id and test score:
/*After the following input, then enter 0 to end the input*/
Student ID Test Score Letter Grade
------------ ----------- --------------
1653 77 C
1945 72 C
1020 50 F
1955 92 A
1900 81 B
ABOVE AVERAGE STUDENTS
Ave Test Score Students Above Ave Number of: A's B's C's D's F's
----------- ---------- --------- --- --- --- --- ---
62.00 4 1 1 2 0 1
THE STUDENT WITH THE HIGHEST TEST SCORE
Student ID Test Score Letter Grade
--------- ---------- ------------
1900 0 F
Press any key to continue...
View 1 Replies
View Related
Sep 2, 2013
'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.
Code:
s: accept = false; cin >> char;
if char = "m" goto m;
if char = EOF goto end;
goto s;
m: accept = false; cin >> char;
if char = "m" goto m;
if char = "a" goto a;
if char = EOF goto end;
goto s;
}
[code]....
View 3 Replies
View Related
Jun 25, 2014
Basically I have a text file called words. I'm supposed to extract a word randomly from the file and have the user guess the word according to the definition.
I'm having trouble matching the definition to the word from the text file.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int number;
int count = 0;
string word;
[Code] ....
Here is my text file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 1 Replies
View Related
Jan 5, 2015
Whats wrong with my program ? It always says that coundn't find match operator ? What can i do ? I want to multiply string pay to int HOURS.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main () {
system("color 8e");
string ID,name, address,No, pos ,pay, hanap;
string hours;
[Code] .....
View 3 Replies
View Related
May 19, 2014
In the MSDN, it gives an example using Regex.Matches method:
using System;
using System.Text.RegularExpressions;
public class Example {
public static void Main() {
string pattern = "a*";
string input = "abaabb";
foreach (Match m in Regex.Matches(input, pattern))
Console.WriteLine("'{0}' found at index {1}.",
m.Value, m.Index);
[code]......
I am wondering if string input was an array of strings instead, how would I use Regex.Matches?
What I was thinking about doing is having the input array set to ToString(), input.ToString(), but that doesn't seem to work.
View 9 Replies
View Related
Dec 30, 2013
The compiler says my Rotor's cctor's definition doesn't match it's prototype.
Also, how can I convert my for loops into foreach loops?
Attached is the project.
View 9 Replies
View Related
Mar 6, 2015
I'm supposed to create a "game" that is similar to Candy Crush or Bejeweled. The assignment takes in a .txt file that contains a matrix of values from 1-5 and then assigns each value to a spot in a [10][10] array. Then an Escape Code function prints out colored pixels in place of the number values for each spot, creating a "game board" looking output. Finally, the program is supposed to look for any matches of 3 same-colored pixels and replace them with a white pixel and "XX". Then the program prints the corrected game board with the matches X'd out.
I have it mostly coded, but I've encountered a couple of issues.
1.) I am supposed to label the columns and rows 0-9, and while I have no problem coding the labels for the columns using printf( ), when I try to print the row labels I get a random string of numbers.
2.) I replaced the matches with white pixels by reassigning the value in the array to 7, for which the ANSI Escape Code is white. However, I'm unsure about how to print the "XX" in the same spot.
Here is the input(.txt) file and the output of the program so far:
And here is what I have coded at this point:
Code:
#include <stdio.h>
void printEscapeCode(int c);
int main(void)
{
/* Declare an image array to be gameboard */
int gameboard[10][10];
/* Declare variables and load in how many rows and columns */
int Nrows;
Nrows = 0;
[code]....
View 2 Replies
View Related
Dec 3, 2014
I have an if statement that should either match a text variable that the user has entered and a another text variable that has been got from an array but they won't match even if they are the same,Im at a lost with it.
void displayQuestion(int noQuestion, string questionArray[], string answerarray[], string answer, double scorearray, double finalscore){
cout << questionArray[noQuestion] << endl;
cout << "enter an answer " << endl;
cin >> answer;
[Code] ....
View 1 Replies
View Related
May 12, 2013
I am just learning using class template but I keep getting error unable to match function definition to an existing declaration
template <typename T>
class Homework {
private:
string name;
public:
template <typename T>
void SetName(T val);
[Code] ....
View 10 Replies
View Related
Apr 13, 2013
I've written the following code and keep getting the errors:
Error1error C2244: 'Supermarket<temp>::operator =' : unable to match function definition to an existing declaration
Error2error C2244: 'Supermarket<temp>::setName' : unable to match function definition to an existing declaration
Error3error C2244: 'Supermarket<temp>::setArea' : unable to match function definition to an existing declaration
#ifndef SUPERMARKET_H
#define SUPERMARKET_H
#include<string>
#include<iostream>
using namespace std;
[Code] .....
I moved the files to the .h file, and now I'm getting
Error2error LNK1120: 1 unresolved externals
View 11 Replies
View Related
Feb 4, 2013
How to display the record that match for the duplicate items in a Listview. I use C# with linq queries.
View 1 Replies
View Related