C/C++ :: Repeated Numbers In A Matrix?

Apr 18, 2014

Given the matrix MxN, check if there are repeated numbers.

View 8 Replies


ADVERTISEMENT

C++ :: Count The Repeated Numbers?

Jul 12, 2013

I am using this code that to check a set of values from a text file and show it on the output.

Code: void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;

[code]....

I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-

Code:

The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

[code]....

So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -

Code:

The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6

[code]....

How can I do that?

View 3 Replies View Related

C++ :: How To Count Repeated Numbers In Array

Jan 30, 2015

So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int inputs[30];
int numofloops;
int maxvalue = inputs[0];

[Code]...

View 1 Replies View Related

C :: Card Shuffling - How Numbers Are Not Repeated In Function

Jan 27, 2014

I found a card shuffling function on a long dead thread.

Code:
for (int x = 52; x > 0 ; x--)
{ y = rand() % x;
temp = deck[x];
deck[x] = deck[y];
deck[y] = temp; }

I do not understand how numbers are not repeated in the function. It seems like it would be possible to get 2 cards with the same number with the above function.

I also am getting incorrect numbers. It seems like I should only get numbers between 1 and 52 (which is what I want). However, I am getting the number 0, and some number between 1 and 52 will be missing, but I will have a total of 52 unique numbers.

I played around with using 51 instead of 52, x > 1, and changed to --x and none of those produced the desired results.

View 5 Replies View Related

C/C++ :: Placing Numbers In Random Positions In Matrix?

Oct 30, 2014

i have a problem with a bit of code (part of an as-yet incomplete program that creates a sort of maze with 10 roadblocks, and then finds the shortest route to the exit.

I don't know what it means, to put tags around my code, but I shall try to point out the problem bit clearly. It is not a long segment. This part is all working fine and printing the messages the user needs to see initially:

#include <stdio.h>
#include <stdlib.h>
int main() {
printf("The number -1 shall represent the position of the robot in the matrix.
"
"The number 99 shall represent the position of the exit.
"
"The number 100 shall represent all blocks.
"
"All other numbers represent the number of moves required to reach the occupied space from the robot's position.
");

Below is where is goes bad, and I really am not sure why. The program says it has stopped responding and gets grayed out, and then I get the error message, "An access violation (Segmentation fault) raised in your program.

I have tried using the debugger, and it only tells me it found 0 errors and 0 warnings.

srand(time(NULL));
int initialmatrix [8] [8];
initialmatrix [0] [7] = 99;
int numberofblocks=0;
int randomrow;

[code]....

View 5 Replies View Related

C++ :: Using OOP To Implement Matrix Class That Provide Basic Matrix Operations

Mar 27, 2013

i want to know how i can solve this question? do i need to create a class or write the program codes.

View 12 Replies View Related

C++ :: Accept Matrix As Argument And Display Its Multiplication Matrix

Jun 1, 2014

I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.

View 1 Replies View Related

C++ :: How To Find Repeated Words

Aug 3, 2014

I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.

View 7 Replies View Related

C++ :: Repeated Digit In Integer

Oct 19, 2013

this code :

#include <cstdlib>
#include <iostream>
#define TRUE 1
#define FALSE 0
using namespace std;
typedef int Bool;

[Code] ....

Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.

so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????

View 3 Replies View Related

C++ :: Print Repeated Array Of 2D?

Mar 23, 2014

Printing duplicate 2D array elements

if for 1D array

for (int i = 0; i<0; i++){
for (int j = i+1; j<0; i++)
{
if (arra[i] == arra[j]){
cout<<arra[i]<<endl
}
}
}

how would i do for 2D

View 5 Replies View Related

C++ :: Counting The Repeated Number?

Jul 12, 2013

This function check a set of values from a text file and show it on the output.

void MatchNumber(int b){
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");

[Code]......

I want to calculate how many times the number is repeated. So I have used freq[num] in that function. But I am getting the output like this-

The common number is = 5
The 5 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

The common number is = 9
The 9 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

So the value of freq[num] only shows 1 instead of calculating the number of repetition.

View 3 Replies View Related

C/C++ :: Using Strings To Find Out If A Name Is Repeated?

Feb 10, 2014

I have to write a code that will read in n amount of names and the names. Then it will tell me if the first name entered has been repeated or not.

This is my input:

5 Bush Reagan Lincoln Bush Obama

This is my output:

First name in list is not repeated.
First name in list is not repeated.
First name in list is repeated.
First name in list is not repeated.

I would like to just give one answer; if it is repeated then the output should simply be "First name in list is repeated."

If the answer is that it was not repeated, I would like the output to say once "First name in list is not repeated."

// lastnames.c

#include <stdlib.h>
#include <stdio.h>
int main(void) {
char FIRST[25];

[code]....

View 2 Replies View Related

C/C++ :: Assign A Matrix To Submatrix Of A Bigger Matrix?

Feb 27, 2012

I want to assign a matrix to submatrix of a bigger matrix.

ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
        A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
    for(size_t j=0;j<B.size2();++j)
        B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;  

and it works.

but if the matrix is compressed_matrix type, there's something with it. the error log as below:

Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted

I'm not sure this is a bug or not.

View 2 Replies View Related

C++ :: Repeated Word Detection Program?

Mar 6, 2015

In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:

Code:
#include "std_lib_facilities.h"
int main() {
int number_of_words = 0;
string previous = " "; // previous word; initialized to "not a word"
string current; // current word
while (cin >> current) // read a stream of words

[Code].....

The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).

Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all.

View 3 Replies View Related

C/C++ :: Writing Repeated Lines To A File?

Aug 26, 2014

I am working on a problem for the CS50 online course through the Harvard web site. I am trying to re-size a bmp image. They gave us a small program that copies a bmp image and we are to modify it to re-size the image. Here is the page [URL]..... Any way I am trying to move the file position indicator backwards so I can read the same line from the input file. So I can resize the file vertically I have the image resized horizontally but it keeps over writing the same lines vertically.

/**
* bmp.h
*
* Computer Science 50
* Problem Set 5

[Code]...

View 4 Replies View Related

C/C++ :: Finding First Non-repeated Digit In Array

Aug 26, 2014

With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".

This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0.
nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....

for (n=0; n<sizeof(digits)/sizeof(int); n++) {
if(repCount<2) {
// nonRepCount=0;
for (o=n+1; o<sizeof(digits)/sizeof(int); o++)

[Code] .....

View 1 Replies View Related

C :: Replace Repeated Elements Within 2D (10x10) Int Array

Mar 20, 2014

I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.

Code:
46 for(row=0;row<10;row++)
47 {
48 for(col=0;col<10;col++)
49 {
50 board[row][col]=rand()%4+1; //filling matrix here

[Code] .....

I know there must exist a much more elegant approach than listing out all permutations.

View 1 Replies View Related

C :: Read In N / Then N Words And Check To See If First Word Is Repeated

Sep 23, 2013

Read in n, then n lastnames, and check to see if the first in the list is ever repeated again.Here's what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
int strcmp(char *w1, char *w2);
int main() {
int j, n;
char string1[30], string2[30];
}

[code]....

I see the problem is that it lies within n amount of string that I am not going through every string to compare to the first one.How will do compare every string to the first one?

Current output:
3
alex
alex
alex
Not repeated

3
alex
ash
peter
Not repeated

View 2 Replies View Related

C++ :: Deleting Repeated Lines In A Text File

Jul 30, 2014

I have a text file with repeated lines, and i would like to get rid of the duplicate information, an algorithm to achieve this?

Example of my text file (the actual file may be huge, up to 500MB):

+Hello
+Bye
*The sun
-The moon
+Bye
/One coin
+Bye
+Bye
+Hello
*The sun

And i would expect to get something like this:

+Hello
+Bye
*The sun
-The moon
/One coin

I know how to open and read a file with fstream and getline(), but i don't know how to make the comparison.

View 6 Replies View Related

C++ :: Repeated Handling With Different Methods Calls But Same Parameters

Apr 24, 2014

I have several functions doing similar things, inside their implementations, the parameters are the same, but they call different methods.

I want to create one function to make the structure easier, and reduce the duplication. I heard template might be one solution. But I am not sure how to use it in this case.

void GetA(...XXX) {
for()
{

[Code].....

View 1 Replies View Related

C/C++ :: Find Repeated Words In String And Symbols Between Them

Oct 29, 2013

I need to find 2 similar words in one sentence and i need to find how much symbols are between these two words. I can't figure out the algorithm.

For example sentence would be-

This is nice table and nice chair.

Similar words are- nice

Symbols between them are 11 or 8(dont know if space is count as symbol)

int main()    
char text[200],*dist;
printf("Enter one sentence 
 ");
gets(text);

Maybe first of all would be

dist=strtok(text, " ,.!?");
while(dist!=0)
{
 printf("%s
", dist);
 dist=strtok(NULL, " ,.!?");
 }  

and it wil output each word and maybe then can search for similar words if there would be 2 strings then i would use strstr but i dont know how to do with one string.

View 1 Replies View Related

C++ :: Find Matrix P For A Square Matrix A

May 25, 2014

I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....

View 15 Replies View Related

C++ :: Game With Entity Component System - Generalizing Repeated Functions

Dec 20, 2014

I'm working on a game with an entity-component system. I have a Manager class that is handling all of the components by feeding them into vectors set up for each type of component. Right now I have a lot of repeated code for each kind of component.

void add_pos_comp(shared_ptr<Position> pos_comp);
shared_ptr<Position> get_pos_comp(int id);
const vector<shared_ptr<Position>>& get_pos_comps();

void add_vel_comp(shared_ptr<Velocity> vel_comp);
shared_ptr<Velocity> get_vel_comp(int id);
const vector<shared_ptr<Velocity>>& get_vel_comps();

I've tried generalizing this with templates, but I've been confused by how I should organize the collection of vectors for each component. I had it setup so that they were all in an unordered_map, but how to get the templated functions to find the right map slot to use based simply on the template's parameters.

The full project is here for reference: [URL] ....

View 2 Replies View Related

C++ :: How To Convert Compact Form Of Matrix Into Matrix Form

Oct 4, 2014

3 3
2 1 3 2 3
1 0 2
1 2 6

First line shows row and column number

First index of the second line tells the number of non-zero entries of the first row and second index tell the column number where the non zero entry is placed

for 1st row of matrix:

non-zero entries=2
column number=1
non-zero entry=3
column number=2
non-zero entry=2

covert this in the given form
0 3 3
2 0 0
0 0 6

View 1 Replies View Related

C++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C :: Finding Written Numbers In A String And Converting Them To Decimal Numbers

Jun 20, 2013

User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.

I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.

Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;

[Code] .....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved