| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:函数表达式求值
只看楼主 加入收藏
小小珊玉
Rank: 2
等 级:论坛游民
帖 子:19
专家分:18
注 册:2012-7-18
结帖率:40%
收藏
已结贴  问题点数:20 回复次数:9 
函数表达式求值
这是求一个函数表达式值的程序,可是运算结果老是零?
求帮助!
#include <iostream>
using namespace std;

const int MAX = 18;

int M[MAX];
int N[MAX];int S[3][3]={2,2,3,4,5,5,6,7,8};
int X[3][3]={2,2,3,4,5,5,6,7,8};
int Y[3][3]={2,2,3,4,5,5,6,7,8};
int Z[3][3]={2,2,3,4,5,5,6,7,8};
int sum1( int i,int S[3][3],int X[3][3])
{
    int sum = 0;
    for( int j = 13; j <=0; --j)
        sum += ( S[i-1][j] - X[i-1][j]);
    return sum;
}

int sum1( int i, int k,int S[3][3],int X[3][3])
{
    int sum = 0;
    for( int j = 13; j < k; --j)
        sum += ( S[i][j] - X[i][j]);
    return sum;
}

int max1( int i)
{
    int max = sum1( i, 13,S,X);
    for( int k = 12; k <= 0; --k)
        if( sum1( i, k,S,X) > max)
            max = sum1( i, k,S,X);
    return max;
}

int getM( int i)
{
    M[i] = sum1( i,S,X) + max1( i);
    return M[i];
}
int sum2( int i,int Y[3][3],int Z[3][3])
{
    int sum = 0;
    for( int j = 13; j <=0; --j)
        sum += ( Y[i-1][j] - Z[i-1][j]);
    return sum;
}

int sum2( int i, int k,int Y[3][3],int Z[3][3])
{
    int sum = 0;
    for( int j = 13; j < k; --j)
        sum += ( Y[i][j] - Z[i][j]);
    return sum;
}

int max2( int i)
{
    int max = sum2( i, 13,Y,Z);
    for( int k = 12; k <= 0; --k)
        if( sum2( i, k,Y,Z) > max)
            max = sum2( i, k,Y,Z);
    return max;
}

int getN( int i)
{
    N[i] = sum2( i,Y,Z) + max2( i);
    return N[i];
}
int main()
{

    for( int i = 0; i < MAX; ++i)
        getM(i);
    for(int j=0;j<MAX;++j)
        getN(j);
    double s1=0;
            s1=s1+getM(i);
    double s2=0;
             s2=s2+getN(j);
    float u=(s1/120)*14.58/220;
    float d=(s2/120)*14.61/220;
    for(int k=0;k<=MAX;k++)
    {    cout<<"上行阶段(A13-A0)每时刻净上车人数分别是:"<<M[k]<<endl;
    cout<<"下行阶段(A0-A13)每时刻净上车人数分别是:"<<N[k]<<endl;}
        cout<<"一共需要"<<u+d<<"辆车。"<<endl;


 return 0;
}
搜索更多相关主题的帖子: 表达式 return include 
2012-07-18 11:25
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9024
专家分:54030
注 册:2011-1-18
收藏
得分:3 
13 还点呐
2012-07-18 12:08
柚子白
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2012-7-18
收藏
得分:3 
能把题目放上来看看吗,只看程序有点困难啊,而且没有注释。
2012-07-18 15:15
遗失的部落
Rank: 2
等 级:论坛游民
帖 子:30
专家分:55
注 册:2012-4-6
收藏
得分:3 
咋没有注释呢   
2012-07-18 15:29
小小珊玉
Rank: 2
等 级:论坛游民
帖 子:19
专家分:18
注 册:2012-7-18
收藏
得分:0 
#include
using namespace std;

const int MAX = 18;

int M[MAX];
int N[MAX];
    int S[18][14]={{371,60,52,43,76,90, 48, 83, 85, 26, 45, 45, 11, 0},
        {1990, 376, 333,256, 589, 594, 315, 622, 510, 176, 308, 307, 68},
        {3626, 634, 528, 447, 948, 868, 523, 958, 904, 259, 465, 454, 99, 0},
        {2064, 322, 305, 235, 477, 549, 271, 486, 439, 157, 275, 234, 60, 0},
        {1186 ,205, 166, 147, 281, 304, 172, 324, 267, 78 ,143 ,162 ,36 ,0},
        {923 ,151 ,120 ,108 ,215 ,214 ,119 ,212 ,201 ,75 ,123 ,112 ,26 ,0},
        {957,181,157,133,254,264,135,253,260,74,138,117,30,0},
        {873,141,140,108,215,204,129,232,221,65,103,112,26,0},
        {779,141,103,84,186,185,103,211,173,66,108,97,23,0},
        {623,104,108,82,162,180,90,185,170,49,75,85,20,0},
        {635,124,98,82,152,180,80,185,150,49,85,85,20,0},
        {1493,299,240,199,396,404,210,428,390,120,208,197,49,0},
        {2011,379,311,230,497,479,296,586,508,140,250,259,61,0},
        {691,124,107,89,167,165,108,201,194,53,93,82,22,0},
        {350,64,55,46,91,85,50,88,89,27,48,47,11,0},
        {304,50,43,36,72,75,40,77,60,22,38,37,9,0},
        {209,37,32,26,53,55,29,47,52,16,28,27,6,0},
        {19,3,2,5,5,3,5,5,1,3,2,1,0}
};
 int X[18][14]={{0,8,9,13,20,48,83,26,45,45,11,0},
 {0,99,105,164,239,588,542,800,407,208,300,288,921,615},
 {0,205,227,272,461,1058,1097,1793,801,496,560,636,1871,1459},
 { 0,106,123,169,300,634,621,971,440,245,339,408,1132,759},
 {0,81,75,120,181,407,411,551,250,136,187,233,774,483},
 {0,52,55,81,136,299,280,422,178,105,153,167,532,385},
 { 0,54,58,84,131,321,291,420,196,119,159,153,534,340},
 {0,46,49,71,111,263,256,389,164,111,134,148,488,333},
 { 0,39,41,70,103,221,197,297,137,85,113,116,384,263},
 {0,36,39,47,78,189,176,339,139,80,97,120,383,239},
 {0,36,39,57,88,209,196,339,129,80,107,110,353,229},
 {0,80,85,135,194,450,731,335,157,255,251,800,557},
 {0,110,118,171,257,694,573,957,390,253,293,378,1228,793},
 {0,45,48,80,108,237,231,390,150,89,131,125,428,336},
 {0,22,23,34,63,116,108,196,83,48,64,66,204,139},
 {0,16,17,24,38,80,84,143,59,34,46,47,160,117},
 {0,14,14,21,33,78,63,125,62,30,40,41,128,92},
 {0,3,3,5,8,18,17,27,12,7,9,9,32,21},
 };
 int Y[18][13]={{22.3,4,2,4,4,3,3,3,1,1,0,0},
 {795,143,167,84,151,188,109,137,130,45,53,16,0},
 {2328,380,427,224,420,455,272,343,331,126,138,45,0},
 {2706,374,492,224,404,532,333,345,354,120,153,46,0},
 {1556,204,274,125,235,308,162,203,198,76,99,27,0},
 {902,147,183,82,155,206,120,150,143,50,59,18,0},
 {847,130,132,67,127,150,108,104,107,41,48,15,0},
 {770,97,126,59,102,133,97,102,104,36,43,13,0},
 {839,133,156,69,130,165,101,118,120,42,49,15,0},
 {1110,170,189,79,169,194,141,152,166,54,64,19,0},
 {1837,260,330,146,305,404,229,277,253,95,222,34,0},
 {3020,474,587,248,468,649,388,432,452,157,205,56,0},
 {1966,350,399,204,328,471,289,335,342,122,132,40,0},
 {939,130,165,88,138,187,124,143,147,48,56,17,0},
 {640,107,126,69,112,153,87,102,94,36,43,13,0},
 {636,110,128,56,105,144,82,95,98,34,40,12,0},
 {294,43,51,24,46,58,35,41,42,15,17,5,0}
};
int  Z[18][13]={{0,2,1,1,6,7,7,5,3,4,2,3,9},
 {0,70,40,40,184,205,295,147,93,109,75,108,271},
 {0,294,156,157,710,780,849,545,374,444,265,373,958},
 {0,266,158,149,756,827,856,529,367,428,237,376,1167},
 {0,157,100,80,410,511,498,336,199,276,136,219,556},
 {0,103,59,59,246,346,320,191,147,185,96,154,438},
 {0,94,48,48,199,238,256,175,122,143,68,128,346},
 {0,70,40,40,174,215,205,127,103,119,65,98,261},
 {0,75,43,43,166,210,209,136,90,127,60,115,309},
 {0,84,48,48,219,238,246,155,112,153,78,118,346},
 {0,110,73,63,253,307,341,215,136,167,102,144,425},
 {0,175,96,106,459,617,549,401,266,304,162,269,784},
 {0,330,193,194,737,934,1061,606,416,949,278,448,1249},
 {0,223,129,150,635,787,690,505,304,423,246,320,1010},
 {0,113,59,59,266,306,290,201,147,155,86,154,398},
 {0,75,43,43,186,230,219,146,90,127,70,95,319},
 {0,73,41,42,190,243,192,132,107,123,67,101,290},
 {0,35,20,20,87,108,92,69,47,60,33,49,36}
};

int sum1( int i,int S[18][14],int X[18][14])//求s[i-1][j]-x[i-1][j]当j从0到13的和
{
    int sum = 0;
    for( int j = 0; j <=13; j++)
        sum += ( S[i-1][j] - X[i-1][j]);
    return sum;
}

int sum1( int i, int k,int S[18][14],int X[18][14])//当j从0到k时求s[i][j]-x[i][j]的和
{
    int sum = 0;
    for( int j = 0; j < k; j++)
        sum += ( S[i][j] - X[i][j]);
    return sum;
}

int max1( int i)                                    //求k取何值时sum1的最大值
{
    int max = sum1( i, 14,S,X);
    for( int k = 0; k <= 13; k++)
        if( sum1( i, k,S,X) > max)
            max = sum1( i, k,S,X);
    return max;
}

int getM( int i)                                //s[i-1][j]-x[i-1][j]当j从0到13的和与sum1的最大值
{
    M[i] = sum1( i,S,X) + max1( i);
    return M[i];
}
int sum2( int i,int Y[18][13],int Z[18][13])//求y[i-1][j]-z[i-1][j]当j从0到13的和
{
    int sum = 0;
    for( int j = 0; j <=12; j++)
        sum += ( Y[i-1][j] - Z[i-1][j]);
    return sum;
}

int sum2( int i, int k,int Y[18][13],int Z[18][13])//当j从0到k时求y[i][j]-z[i][j]的和
{
    int sum = 0;
    for( int j = 0; j < k; j++)
        sum += ( Y[i][j] - Z[i][j]);
    return sum;
}

int max2( int i)                            //求k取何值时sum2的最大值
{
    int max = sum2( i, 13,Y,Z);
    for( int k =0; k <=12; k++)
        if( sum2( i, k,Y,Z) > max)
            max = sum2( i, k,Y,Z);
    return max;
}

int getN( int i)                                        //y[i-1][j]-z[i-1][j]当j从0到13的和与sum2的最大值
{
    N[i] = sum2( i,Y,Z) + max2( i);
    return N[i];
}
int main()
{
        double s1=0, s2=0;
        for( int i = 0; i <=17; ++i)
                    s1=s1+getM(i);
                    s2=s2+getN(i);
        int u=((s1/120)*14.58)/220+1;
        int d=((s2/120)*14.61)/220;
                cout<<"上行阶段(A13-A0)"<
2012-07-18 16:22
★逆时光
Rank: 2
来 自:浙江
等 级:论坛游民
帖 子:11
专家分:42
注 册:2011-12-29
收藏
得分:3 
膜拜
2012-07-19 15:49
瑶光一笑
Rank: 1
等 级:新手上路
帖 子:6
专家分:6
注 册:2012-7-18
收藏
得分:3 
大神!
2012-07-20 11:05
jiantiewen
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:61
专家分:307
注 册:2012-6-22
收藏
得分:3 
楼主真会整人。
2012-07-21 21:51
z00o00
Rank: 2
等 级:论坛游民
帖 子:4
专家分:10
注 册:2012-7-21
收藏
得分:3 
循环错的太离谱了吧
2012-07-21 22:28
drci
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-9-26
收藏
得分:0 
看的有点晕了
2012-09-27 18:05
快速回复:函数表达式求值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026094 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved