V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
long1
V2EX  ›  Sublime Text

sublime 坑点?

  •  
  •   long1 · 2018-11-27 18:44:15 +08:00 · 3506 次点击
    这是一个创建于 2169 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近做 os 家庭作业,sublime Text3 编辑 c++程序,遇到了输入读不完就退出了运行了。

    只是用了指针来实现?求大佬指点小弟。

    #include <bits/stdc++.h>
    #include <stdio.h>
    #include <stdlib.h>
    #define mp make_pair
    #define fi first
    #define se second
    #define llt long long 
    using namespace std;
    
    char s[10][1100];
    const int WORKSIZE=32;
    typedef pair<int,int> pii;
    pii WorkBlock[WORKSIZE];
    
    int mixnTime;
    int startTime=0;
    int useSize=0;
    struct PBlock{
    	int id;
    	int priority;
    	int time;
    	int blocksize;
    	struct PBlock* nxt;
    };
    
    
    struct PBlock* readying;
    
    void add(struct PBlock* tmp){
    	// 队列为空
    	if(readying == NULL){
    		readying = tmp;
    		return ;
    	}
    
    	//队首优先级小于 tmp
    	if((readying->priority)<(tmp->priority)){
    		tmp->nxt = readying;
    		readying = tmp;
    		return;
    	}
    
    	struct PBlock* pre=readying;
    	struct PBlock* suf=pre->nxt;
    
    	//cout<<(pre->priority)<<" ";
    	while(suf!=NULL){
    		if((suf->priority)<(tmp->priority))
    			break;
    		pre = suf;
    		suf = pre->nxt;
    		//cout<<(pre->priority)<<" ";
    	}
    
    	tmp->nxt = pre->nxt;
    	pre->nxt = tmp;
    	//cout<<pre->priority<<endl;
    	return ;
    }
    
    void Print_Line(){
    	for(int i=0;i<170-3;++i)
    		printf("%c","-\n"[i==170-4]);
    }
    
    void Print(){
    	printf("Time: %d\n",startTime );
    
    	Print_Line();
    	printf("| %s |",s[0]);
    	for(int i=0;i<WORKSIZE;++i)
    		printf(" %2d |",i);
    	printf("\n");
    
    	Print_Line();
    	printf("| %s |",s[1]);
    	for(int i=0;i<WORKSIZE;++i)
    		if(WorkBlock[i].se>0)printf(" %2d |",WorkBlock[i].fi);
    		else printf(" %2c |",' ');
    	printf("\n");
    
    	Print_Line();
    }
    
    void Running(){
    
    	if((readying==NULL)||WORKSIZE-useSize<(readying->blocksize)){
    		int costTime=mixnTime;
    		mixnTime=0x3f3f3f3f;
    		for(int i=0;i<WORKSIZE;++i){
    			if(WorkBlock[i].se==0) continue;
    			WorkBlock[i].se-=costTime;
    			if(WorkBlock[i].se==0) --useSize;
    			else mixnTime=min(mixnTime,WorkBlock[i].se);
    		}
    		//cout<<mixnTime<<endl;
    		Print();
    		startTime+=costTime;
    		return;
    	}
    
    	for(int i=0;i<WORKSIZE;++i){
    		if((readying->blocksize)==0)break;
    
    		if(WorkBlock[i].se>0)continue;
    		WorkBlock[i].fi=readying->id;
    		WorkBlock[i].se=readying->time;
    		++useSize;
    		--(readying->blocksize);
    	}
    
    	mixnTime=min(mixnTime,readying->time);
    	struct PBlock* tmp=readying->nxt;
    	free(readying);
    	readying=tmp;
    }
    int main(){
    
    	scanf("%s",s[0]);
    	scanf("%s",s[1]);
    	//freopen("in.txt","r",stdin);
    	memset(WorkBlock,0,sizeof WorkBlock);
    
    	int BlockSize;
    
    	cin>>BlockSize;
    	for(int i=0;i<BlockSize;++i){
    		struct PBlock* tmp = (struct PBlock*) malloc(sizeof (struct PBlock*));
    		tmp->nxt = NULL;   
    		scanf("%d%d%d%d",&(tmp->id),&(tmp->priority),&(tmp->time),&(tmp->blocksize));
    		//cout<<(tmp->id)<<" "<<(tmp->priority)<<" "<<(tmp->time)<<endl;
    		add(tmp);
    	}
    	//cout<<1<<endl;
    	while((useSize>0)||(readying!=NULL))
    	    Running();
    
    	return 0;
    }
    
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5679 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 06:36 · PVG 14:36 · LAX 22:36 · JFK 01:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.