| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 649 人关注过本帖
标题:大家能看看这个程序出错在哪里吗?本人菜鸟,求各位大神罩罩
只看楼主 加入收藏
linke11002
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-9-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
大家能看看这个程序出错在哪里吗?本人菜鸟,求各位大神罩罩
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<fstream>
#include<ctime>
#include<cstdlib>
using namespace std;

int main()
{
    cout << "请依次输入v,d,T,T_start,T_end"<<endl;
    int v;
    double d;
    cin >> v >> d;
    int A = 0, B = 0;
    int T, T_start, T_end;
    cin >> T >> T_start >> T_end;
    srand(int(time(0)));
    int f[5] = { 0,5,10,15,20 };
   
    int num=0;
    int t_left[10000];
    double y_left[10000];
    double s_left[10000];
   
   
   
    while (T >= T_start&&T <= T_end)
    {
        int j_num;
        int i_num;
        int taxi;
        int w;
        j_num = rand() % 16;
        i_num = j_num + num;


        A = A + j_num;
        int **matrix = (int **) new int *[i_num];
        for (int i = 0; i < i_num; i++)
            matrix[i] = new int[5];
        double * s = new double[i_num];
        double *Y = new double[i_num];

        for (i = 0; i < j_num; i++)
        {
            matrix[i][0] = rand() % 11 + 5;        //t
            matrix[i][1] = rand() % 31;            //S
            int temp = rand() % 5;
            matrix[i][2] = f[temp];                //f
            s[i] = (rand() % 100)*0.01;           //s
            matrix[i][3] = 0;     //F
            matrix[i][4] = 1;     //bool
            
        }
        int j;
        for (i = j_num,j = 0; i < i_num; i++,j++)
        {
            matrix[i][0] = t_left[j];
            s[i] = s_left[j];
            Y[i] = y_left[j];
            matrix[i][4] = 1;
        }
        
        
        if (540 >= T&&T >= 180 || 1020 <= T&&T <= 1080)
            taxi = rand() % 6 + 5;
        else
            taxi = rand() % 11 + 10;
        w = rand() % 11 + 5;

        for (i = 0; i < j_num; i++)
        {
            if (matrix[i][1] <= 3)
                matrix[i][3] = 8;
            else
                matrix[i][3] = 8 + 2 * (matrix[i][1] - 3);
            Y[i] = matrix[i][3] + B*matrix[i][0] + matrix[i][2] - s[i] * d -matrix[i][1]*d;
        }


        int count = 0;

        for (i = 0; i < i_num; ++i)
        {
            if (Y[i]>w&&matrix[i][4]==1)
            {
                count++;
            }   
            
        }



        int one;
        double hehe;
        for (i = 0; i < i_num;i++)
        for (j = 0; j < i_num - i - 1; j++)
        {
            if (Y[j] < Y[j + 1])
            {
                one = matrix[j][0];
                matrix[j][0] = matrix[j+1][0];
                matrix[j + 1][0] = one;    //t


                hehe = s[j];
                s[j] = s[j + 1];
                s[j + 1] = hehe;

                hehe = Y[j];
                Y[j] = Y[j + 1];
                Y[j + 1] = hehe;


            }
        }

        
        if (count >= taxi)
        {
            
            for (i = 0; i < taxi; i++)
            {
                matrix[i][4] = 0;
                double temp = s[i] / v;
                if (temp <= matrix[i][0])
                    B++;
            }
            for (i = taxi; i < i_num; i++)
            {
                matrix[i][0]--;
                if (matrix[i][0] == 0)
                    matrix[i][4] = 0;
            }
        }

        else
        {
            
            for (i = 0; i < count; i++)
            {
                matrix[i][4] = 0;
                double temp = s[i] / v;
                if (temp <= matrix[i][0])
                    B++;
            }
            for (i = count; i < i_num; i++)
            {
                matrix[i][0]--;
                if (matrix[i][0] == 0)
                    matrix[i][4] = 0;
            }
        }
        for (i = 0,j=0; i < i_num; i++,j++)
        {
            if (matrix[i][4] == 1)
            {
                y_left[j] = Y[i];
                s_left[j] = s[i];
                t_left[j] = matrix[i][0];
                num++;
               
            }
        }
            
        
        
        delete[]s;
   

        
        delete[]Y;
        for (i = 0; i < i_num; i++)
            delete[] matrix[i];
        delete[] matrix;
        

        T = T + 1;
    }
    double x =(double) B / A;
    cout << B << " " << A;
    cout << endl << x;
    int h;
    cin >> h;
}
搜索更多相关主题的帖子: double include 
2015-09-12 17:45
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:5 
编译信息,这么长的代码人眼怎么看?

一片落叶掉进了回忆的流年。
2015-09-12 23:55
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:5 
要有编译信息。
2015-09-16 08:48
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:5 
vc++编译通过,不知道这个代码要干什么。

能编个毛线衣吗?
2015-09-16 08:52
zhouyuejie
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2015-9-19
收藏
得分:5 
错误多了去了,首先C++里变量是有作用域的比如for语句,你在for(int i=0;...)里声明一个int类型的i它就只有块作用域,只能在本次for循环里访问到,本次for之外的地方要用到i,必须再次声明。即便有些编译器能通过,也会警告(绝对要注意警告,他可能会给你屏蔽掉一些运行时出错的可能)。修改最快的办法是把作用域放在main函数体内,即在main函数内声明一个int i
2015-09-19 09:55
快速回复:大家能看看这个程序出错在哪里吗?本人菜鸟,求各位大神罩罩
数据加载中...
 
   



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

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