|
-
September 23rd, 2002, 12:59 AM
#1
can somebody help me?
question is: i have 10 arrays,each array have 3 numbers.they are all double.
i want to get a number from each array and let their mul is between a range.
for example:a[i]={0.3,0.4,0,0.3}
b[i]={0.2,0.4,0,0.4}
c[i]={0.1,0.4,0,0.5}
d[i]={0.2,0.3,0,0.5}
e[i]={0.7,0.2,0,0.1}
f[i]={0.6,0.2,0,0.2}
g[i]={0.9,0.06,0,0.04}
h[i]={0.55,0.2,0,0.25}
j[i]={0.63,0.17,0,0.2}
k[i]={0.18,0.43,0,0.39}
l[i]={0.23,0.52,0,0.25}
m[i]={0.15,0.4,0,0.45}
n[i]={0.12,0.36,0,0.52}
double t=a[i]*b[i]*c[i]........n[i];
and (t>0.00000001 && t<0.0000001)
print out a[i] to n[i].
find out all the number.
so can u code it in c/c++.
i will online wait for your answer.
and my email address is [email protected]
sports is no nation.
-
September 23rd, 2002, 10:06 AM
#2
If you have a specific question, ask it. We will not do your homework for you.
Jeff
-
September 23rd, 2002, 07:39 PM
#3
i am not a student
sports is no nation.
-
September 24th, 2002, 12:44 AM
#4
Well, this is very confusing. You say you have 10 arrays, and then you list 13 arrays. You say each array has 3 numbers, but in your example there are 4.
You want to multiply the nth element in each array? Well, it looks like you are doing that. I don't know what you are trying to say with "(t>0.00000001 && t<0.0000001)".
If you can provide a code sample that compiles and/or demonstrates the problem, maybe we can help.
Jeff
-
September 24th, 2002, 12:49 AM
#5
here is the code.
int i;
double t;
a[i]={0.3,0.4,0,0.3}
b[i]={0.2,0.4,0,0.4}
c[i]={0.1,0.4,0,0.5}
d[i]={0.2,0.3,0,0.5}
e[i]={0.7,0.2,0,0.1}
f[i]={0.6,0.2,0,0.2}
g[i]={0.9,0.06,0,0.04}
h[i]={0.55,0.2,0,0.25}
j[i]={0.63,0.17,0,0.2}
k[i]={0.18,0.43,0,0.39}
l[i]={0.23,0.52,0,0.25}
m[i]={0.15,0.4,0,0.45}
n[i]={0.12,0.36,0,0.52}
for(int i=0;i<4;i++)
{
if(a[i]==0)//doubleÐÍÅжÏÊDz»ÊÇΪÁ㣬²»Äܸú0±È½ÏµÄ¡£
return 0;
else
t=a[i];
for(int i=0;i<4;i++)
{
if(b[i]==0)
return 0;
else
t* = b[i];
for(int i=0;i<4;i++)
{
if(c[i]==0)
return 0;
else
t* = c[i];
for(int i=0;i<4;i++)
{
if(d[i]==0)
return 0;
else
t* = d[i];
for(int i=0;i<4;i++)
{
if(e[i]==0)
return 0;
else
t* = e[i];
for(int i=0;i<4;i++)
{
if(f[i]==0)
return 0;
else
t* = f[i];
for(int i=0;i<4;i++)
{
if(g[i]==0)
return 0;
else
t* = g[i];
for(int i=0;i<4;i++)
{
if(h[i]==0)
return 0;
else
t* = h[i];
for(int i=0;i<4;i++)
{
if(j[i]==0)
return 0;
else
t* = j[i];
for(int i=0;i<4;i++)
{
if(k[i]==0)
return 0;
else
t* = k[i];
for(int i=0;i<4;i++)
{
if(l[i]==0)
return 0;
else
t* = l[i];
for(int i=0;i<4;i++)
{
if(m[i]==0)
return 0;
else
t* = m[i];
for(int i=0;i<4;i++)
{
if(n[i]==0)
return 0;
else
t* =n[i]; if(t>0.00000001&&t<0.0000001)
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",a[i],b[i],c[i],d[i],e[i],f[i],g[i],h[i],j[i],
k[i],l[i],m[i],n[i]);
else if(t>=0.0000001 && t<0.000001)
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",a[i],b[i],c[i],d[i],e[i],f[i],g[i],h[i],j[i],
k[i],l[i],m[i],n[i]);
else if(t>=0.000001 && t<0.00001)
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",a[i],b[i],c[i],d[i],e[i],f[i],g[i],h[i],j[i],
k[i],l[i],m[i],n[i]);
else
return 1;
}
}
}
}
}
}
}
}
}
}
}
}
}
sports is no nation.
-
September 24th, 2002, 09:53 AM
#6
What is your question?
Jeff
-
September 24th, 2002, 10:17 AM
#7
This cleans up your code a little, and it now compiles. I didn't try to fix any of the logic in it since I don't understand what it's trying to do. At least it should be a better starting point.
Code:
#include <iostream>
double go()
{
const int ROWS = 13;
const int COLS = 4;
double ary[ROWS][COLS]= {
{0.3,0.4,0,0.3},
{0.2,0.4,0,0.4},
{0.1,0.4,0,0.5},
{0.2,0.3,0,0.5},
{0.7,0.2,0,0.1},
{0.6,0.2,0,0.2},
{0.9,0.06,0,0.04},
{0.55,0.2,0,0.25},
{0.63,0.17,0,0.2},
{0.18,0.43,0,0.39},
{0.23,0.52,0,0.25},
{0.15,0.4,0,0.45},
{0.12,0.36,0,0.52}
};
for(int c = 0; c < COLS; ++c)
{
double t = 0;
int r;
for(r = 0; r < ROWS; ++r )
{
if( 0 == ary[r][c] )
{
return 0;
}
t *= ary[r][c];
}
for(r = 0; r < ROWS; ++r )
{
std::cout << ary[r][c] << ', ';
}
std::cout << std::endl;
}
return 1;
}
int main()
{
go();
return 0;
}
-
September 24th, 2002, 08:58 PM
#8
code
// zucai.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
const int n=3;
int i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12;
double sum;
double a[n]={0.39,0.32,0.29};
double b[n]={0.46,0.29,0.25};
double c[n]={0.62,0.38,0.01};
double d[n]={0.03,0.45,0.53};
double e[n]={0.10,0.46,0.44};
double f[n]={0.59,0.39,0.02};
double g[n]={0.10,0.46,0.44};
double h[n]={0.43,0.46,0.11};
double j[n]={0.50,0.07,0.43};
double k[n]={0.22,0.38,0.40};
double l[n]={0.04,0.43,0.52};
double m[n]={0.93,0.05,0.02};
double o[n]={0.73,0.05,0.21};
for(i0=0;i0<n;i0++)
{
//sum =a[i];
for(i1=0;i1<n;i1++)
{
//sum *=b[j];
for(i2=0;i2<n;i2++)
{
for(i3=0;i3<n;i3++)
{
for(i4=0;i4<n;i4++)
{
for(i5=0;i5<n;i5++)
{
for(i6=0;i6<n;i6++)
{
for(i7=0;i7<n;i7++)
{
for(i8=0;i8<n;i8++)
{
for(i9=0;i9<n;i9++)
{
for(i10=0;i10<n;i10++)
{
for(i11=0;i11<n;i11++)
{
for(i12=0;i12<n;i12++)
sum =a[i0]*b[i1]*c[i2]*d[i3]*e[i4]*f[i5]*g[i6]*h[i7]*j[i8]*k[i9]*l[i10]*m[i11]*o[i12];
if(sum>0.00000001 && sum<0.0000001)
printf("first:" "%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f\n",a[i0],b[i1],c[i2],d[i3],e[i4],f[i5],g[i6],h[i7],j[i8],k[i9],l[i10],m[i11],o[i12]);
else{
if (sum>=0.0000001 && sum<0.000001)
printf("second:" "%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f\n",a[i0],b[i1],c[i2],d[i3],e[i4],f[i5],g[i6],h[i7],j[i8],k[i9],l[i10],m[i11],o[i12]);
else {
if (sum>=0.000001 && sum<0.00001)
printf("third:" "%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f,%4.2f\n",a[i0],b[i1],c[i2],d[i3],e[i4],f[i5],g[i6],h[i7],j[i8],k[i9],l[i10],m[i11],o[i12]);
else
continue;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
system("pause");
return 0;
}
sports is no nation.
-
September 24th, 2002, 10:39 PM
#9
I still don't see a question here.
Jeff
-
September 24th, 2002, 10:57 PM
#10
I understand your meaning . but I dont know what are you question ? you already code it out.
-
September 24th, 2002, 11:00 PM
#11
Maybe it's because there isn't any, jfaust
lfj, do yourself a favour, formulate a clear and elaborate question. Otherwise, we can only be mystified by the lack of information in your post.
Martin Breton
3D vision software developer and system integrator.
-
September 25th, 2002, 01:14 AM
#12
ok.
Do u know chinese?My English is so poor,so i am hard to explain
my meaning.So here,i try to do my best .
I want to input 13 arrays,and each array have 3 items.They r all input by keyboard.The programm is trying to find out all the items
in each array can make their mul in the range ,and then try to printing out them.Just like the coder i were wrote.But i found it's very slow to show all .How can it be faster?And make the result printed like that show all the first,and then show all the second,third,ect.
sports is no nation.
-
September 25th, 2002, 01:53 AM
#13
Re: ok.
Originally posted by lfj
Do u know chinese?My English is so poor,so i am hard to explain
my meaning.So here,i try to do my best .
I want to input 13 arrays,and each array have 3 items.They r all input by keyboard.The programm is trying to find out all the items
in each array can make their mul in the range ,and then try to printing out them.Just like the coder i were wrote.But i found it's very slow to show all .How can it be faster?And make the result printed like that show all the first,and then show all the second,third,ect.
Instead of trying to explain, how about giving us a sample of what is input, and what is output? Not in code, just numbers and a visual example. For example here is a question that is formulated correctly:
I would like to write a program that eliminates duplicates. For example:
{1,2,3,4,4,5,2} --> {1,2,3,4,5}
{0,0,0,1} --> {0,1}
(Then question is followed by some code)
Also, is there really a need for 13 to explain what the problem is? Why not first try 2 or 3? The code already is confusing, so cut it down to just 2 or 3 of these arrays. Trying to explain to us in C++ isn't going to be much help.
Regards,
Paul McKenzie
-
September 25th, 2002, 02:32 AM
#14
that's great
input:
a[n]={3,5,6}
b[n]={4,6,9}
c[n]={7,9,4}
****************
sum=a[i]*b[j]*c[k]
for example:
(sum>50 && sum<100)
printf("%d,%d,%d\n",a[i],b[j],c[k])
(sum>100 && sum <200)
printf("%d,%d,%d\n",a[i],b[j],c[k])
just likt that.
sports is no nation.
-
September 25th, 2002, 04:35 AM
#15
Hi lfj
Your problem is a combination problem. I re-state the problem as follow: find all the combinations of 10 out of 3 (10 positions <=> your 10 array, 3 state <=> 0, 1, 2 = the indices to the double in each array). For these sort of combination it is best to solve by recursive.
The idea is we change the state of each pos one at a time, until all states are covered. Let take an example of 2 states and 3 pos (for short)
Pos_: 0 1 2 -> 0 1 2 -> 0 1 2 -> 0 1 2 -> 0 1 2
State: 0 0 0 -> 1 0 0 -> 1 1 0 -> 1 1 1 -> 0 1 1
Notice that for each step the states of the current step differs the states of the previous step in AT MOST one position. That's the rule.
Here is the code: (I did not check the syntax correctness of it. You got the idea and please help me to do it)
Code:
#define MAX_STATE 2 // 0 to 2
#define MAX_POS = 10
// your array
double
n0[3] = {...},
n1[3] = {...},
...
n9[3] = {...};
int States[MAX_POS-1] = {0, 0, ...0}; // initial state
double* A[MAX_POS-1] = {n0, n1, ... n9};
bool CheckResult(doulbe result, double minVal, double maxVal)
{
// do what ever kind of check you want here
// also print out whatever you want to print here
// example
// if (minVal <= result && result <= maxVal)
// print whatever you interested in here
}
void DoMul(int curPos, double minVal, double maxVal)
{
int pos;
// flag for us to stop the recursive
// we stop when the states at every pos is zero
bool stop = true;
double result = 1;
for (pos = 0 ; pos < MAX_POS ; ++pos)
{
result *= A[pos][States[pos]];
if (States[pos] != 0)
stop = false;
}
// CheckResult will do the comparision and output
CheckResult(result, minVal, maxVal);
if (stop)
return;
// try to increase the state of the current pos
if (State[curPos] < MAX_STATE)
++States[curPos]
else // we need to find out the next pos to increase
for (pos = curPos ; pos < MAX_POS ; ++pos)
if (States[pos] < MAX_STATE) // found the right pos now
{
curPos = pos;
++States[curPos];
DoMul(curPos, minVal, maxVal);
}
// if we got here it means all pos reach the MAX_STATE
// then we set the State of the current pos back to 0
States[curPos] = 0;
DoMul(curPos, minVal, maxVal);
}
Even better if you have access to STL, use the next_permutation to calculate the states, the code will be much shorter.
Last edited by TruBic; September 25th, 2002 at 07:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|