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
ADVERTISEMENT
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
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
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
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
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
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
Apr 18, 2014
Given the matrix MxN, check if there are repeated numbers.
View 8 Replies
View Related
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
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
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
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
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
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
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
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
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
Nov 1, 2014
I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.
Code:
#include<stdio.h>
void display(int array[],int size) {
int i;
[Code]....
With this code I want to print the five elements from the element present in [0][4].
But shows an error that
Code:
D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?
View 3 Replies
View Related
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
Oct 13, 2014
How can i print out the SECOND MIN number and MAX number without using array?
cout << "Please input a positive integer: ";
cin >> input;
min = input, max = input, secondmin = input;
do {
cout << "Please input a positive integer: ";
cin >> input;
[Code] .....
View 7 Replies
View Related
Nov 10, 2014
At the bottom I have a loop that cout FI,XC,XL,I while going through the loop but when it prints its uneven and setw cant fix it. How do I print values of FI,XC,XL & I to an array so they are aligned.
#include <iostream>
#include <string>
#include <cmath>
#include "projectfunctions.h"
#include <iomanip>
using namespace std;
const double PI=acos(-1);
[Code] ....
View 4 Replies
View Related
Jan 11, 2014
Given an array with integer values in the range [0, 100], print the values by popularity (number of time it appears in the array).
example: array: 60, 60, 70, 80, 80, 80, 80, 100;
output: 80 80 80 60 60 70 100.
complexity restriction: should be linear.cant use advance data structure like lists or hashmaps, only arrays. structs are not allowed.
my idea: to build counter array of buckets of size 101, and count each value.then i need to sort the counter array(its still linear), but how i can keep track that the value of 80 appeared 3 time?I mean i need to sort the values of the counter with the indexes as well.
View 3 Replies
View Related
Feb 1, 2013
I have a very simple program here, and somehow I can't get it to print out a two-dimensional array. Here's my code:
Code:
#include <stdio.h>
#define MAX_PEOPLE 100
char display_table(int table[MAX_PEOPLE][MAX_PEOPLE], int n);
int main (void) {
int n = 5;
char names[MAX_PEOPLE][4] = {"Ami", "Bob", "Cal", "Dan", "Ion"};
[Code]...
and here's how the printed table should look like when i run the program:
Code:
|Ami Bob Cal Dan Ion
--- --- --- --- --- ---
Ami| 0 1 1 1 0
Bob| 0 0 1 0 0
Cal| 0 0 0 0 0
Dan| 1 0 1 0 1
Ion| 0 1 1 1 0
View 3 Replies
View Related
Jan 12, 2015
when i compile and run it it gives me the number 0 and not the proper number stored in array.
Code:
#include <stdio.h>
int main()
{
int myArray[11] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
}
[code]....
View 4 Replies
View Related
May 2, 2014
I'm having trouble with my for loop near the end of the program was able to print everything else.
Sample Output:
*** end of 27610_Arrays04.cpp program ***
City City Points
--------------- 1---5----10---15---20
Belvidere **********
Freeport ********
Byron ************
Stillman Valley ***************
Rockford *********
*** end of 27610_Arrays04.cpp program ***
Input:
TODO #1: complete the coding of the points array
An integer array of 5 numbers: 10, 8, 12, 15, 9
TODO #2: complete the coding of the cities string array
An string of 5 city names intialized to:
"Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"
Compile-time arrays with initialization lists.
Processing & Output:
TODO #3: complete the coding of the call to the printStars() function
TODO #4: code the printStars() function
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void) {
/* declarations ------------------------------------------------*/
[Code] ....
View 2 Replies
View Related
Nov 25, 2014
In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.
I'm having an hard time to read a pixel map, or atleast ro print it on my main function.
I have a read_xpm function, which is given, therefore, working.
char *read_xpm(char *map[], int *wd, int *ht)
then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:
static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",
[Code]....
I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.
View 3 Replies
View Related