,   CyberForum.ru

: : Min Max - C++

C++ http://www.cyberforum.ru/cpp-beginners/thread545514.html
( ), . ( ) , . () ...
C++ - . ( ) , . ? ) http://www.cyberforum.ru/cpp-beginners/thread545499.html
C++
n, m, a1,, an, b1,,bm, c1,, c30. min(b1, ....,bn )+min(C1, ..., ), |min (a1 , ...., n)|>10, i = 1 + (max(c1c30))2 . ++. !!!
C++
, b, (max (, + b) + max ( , b + c) ) / ( 1 + max ((a , bc, 1.15 )) max - . . 1.15 ( , ) 39
C++ http://www.cyberforum.ru/cpp-beginners/thread545443.html
. 2 . :cry:
C++ . , , . , : : 1. (). 2. ( ) ( 5 3 ) , - 1) (inline) 2) 3) ...

-==-
FAQ
18.04.2012, 17:05     : : Min Max
aidoqa
C++
-
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
 
//Ôó*êöèÿ ïå÷*ò*åò ** ýêð**å ñîäåðæèìîå âåêòîð* ç**÷å*èé vec
//n - ÷èñëî ýëåìå*òîâ âåêòîðå
void out(int n, double * vec);
//Ôó*êöèÿ ïå÷*ò*åò ** ýêð**å ñîäåðæèìîå ì*òðèöû arr
//m - ÷èñëî ñòðîê â ì*òðèöå
//n - ÷èñëî ñòîëáöîâ â ì*òðèöå
void out(int m, int n, double ** arr);
//Ôó*êöèÿ âîçâð*ù*åò min ýëåìå*ò â i-îé ñòðîêå ì*òðèöû arr
double getMinInRow(int i, int n, double ** arr);
//Ôó*êöèÿ âîçâð*ù*åò max ýëåìå*ò â j-îì ñòîëáöå ì*òðèöû arr
double getMaxInCol(int j, int m, double ** arr);
 
int main()
{
    int i, j, N;
    srand(time(0));//Ýòî *óæ*î äëÿ ãå*åð*öèè ñëó÷*é*ûõ ÷èñåë
    //Óê*ç*òåëè ** **øè ì*òðèöû
    double ** arr1 = NULL;
    double ** arr2 = NULL;
    //Óê*ç*òåëü ** âûõîä*îé âåêòîð
    double * res   = NULL;
    cout<<"Enter N : ";cin>>N;
    arr1 = new double *[N];//Âûäåëÿåì ï*ìÿòü ïîä óê*ç*òåëè ** ñòðîêè ì*òðèöû 1
    arr2 = new double *[N];//Âûäåëÿåì ï*ìÿòü ïîä óê*ç*òåëè ** ñòðîêè ì*òðèöû 2
    res = new double[N];////Âûäåëÿåì ï*ìÿòü ïîä ýëåìå*òû âåêòîð* res
    for(i = 0; i < N; i++)
    {
        arr1[i] = new double[N];//Âûäåëÿåì ï*ìÿòü ïîä i-óþ ñòðîêó ì*òðèöû 1
        arr2[i] = new double[N];//Âûäåëÿåì ï*ìÿòü ïîä i-óþ ñòðîêó ì*òðèöû 2
        for(j = 0; j < N; j++)
        {
            //Ãå*åðèðóåì ñëó÷ âåùåñòâå**ûå ÷èñë* â äè*ï*çî*å -N/2 N/2
            arr1[i][j] = (rand()%(10*N) - 5*N)/10.0;
            arr2[i][j] = (rand()%(10*N) - 5*N)/10.0;
        }
    }
    //Ñ÷èò*åì **øå ïðîèèçâåäå*èå:
    //ìè*èì*ëü*îãî ýëåìå*ò* ê*æäîé ñòðîêè ïåðâîé ì*òðèöû ** 
    //**èáîëüøèé ýëåìå*ò ñîîòâåòñòâóþùåãî ñòîëáö* âòîðîé ì*òðèöû
    for(i = 0; i < N; i++)
        res[i] = getMinInRow(i, N, arr1)*getMaxInCol(i, N, arr2);
    //Ïå÷*ò*åì ñãå*åðèðîâ***ûå ì*ññèâû
    cout<<"Array 1 :\n";
    out(N,N,arr1);
    cout<<"Array 2 :\n";
    out(N,N,arr2);
    //Âûâîäèì **ø âåòîð ñòîëáåö îòâåòîâ
    cout<<"Result  :\n";
    out(N,res);
    system("pause");
    //×èñòèì ï*ìÿòü ïðè âûõîäå
    for(i = N - 1; 0 < i; i--)
    {
        delete [] arr1[i];
        delete [] arr2[i];
    }
    delete [] arr1;
    delete [] arr2;
    delete [] res;
    return 0;
}
 
void out(int n, double * vec)
{
    for(int j = 0; j < n; j++)
        cout<<setw((vec[j] < 0 ? 3 : 4))<<setfill(' ')<<vec[j]<<" ";
    cout<<endl;
}
 
void out(int m, int n, double ** arr)
{
    for(int i = 0; i < m; i++)
        out(n, arr[i]);
}
 
double getMinInRow(int i, int n, double ** arr)
{
    //Â**÷*ëå ïîë*ã*åì ÷òî ìè* ýëåìå*ò ð*âå*
    double vmin = arr[i][0];//ïåðâîìó ýëåìå*òó i-é ñòðîêè
    for(int j = 1; j < n; j++)
    {
        //Èùåì ìè* ýëåìå*ò
        if(arr[i][j] < vmin)
            vmin = arr[i][j];
    }
    return vmin;
}
 
double getMaxInCol(int j, int m, double ** arr)
{
    //Â**÷*ëå ïîë*ã*åì ÷òî ìè* ýëåìå*ò ð*âå*
    double vmax = arr[0][j];//ïåðâîìó ýëåìå*òó j-ãî ñòîëáö*
    for(int i = 1; i < m; i++)
    {
        //Èùåì ì*êñ ýëåìå*ò
        if(vmax < arr[i][j])
            vmax = arr[i][j];
    }
    return vmax;
}
:     :  Min      Max    
 
: 08:00. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru