请大佬帮帮忙看看为什么会超时
查看原帖
请大佬帮帮忙看看为什么会超时
459320
QRZ2814514743楼主2023/11/28 20:08
#include <iostream>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char** argv) {
	int AllNum[1000]={0};		//存储数组 
	int LineNum;			//有多少行 
	int ConNum=0;			//有多少个数字
	int m=0,n=0;			//m为缺号数字,n为相同数字 
	
	scanf("%d",&LineNum);		//输入行数 
	
	int i=0;
	while(LineNum){
		cin>>AllNum[i];
		i++;
		
		if(getchar()=='\n'){
			LineNum--;
		}
	}
	
	//判断有多少个数字
	i=0;
	while(1){
		if(AllNum[i]==0 && AllNum[i+1]==0 && AllNum[i+2]==0){
			break;
		}
		i++;
		ConNum++;
	} 

	//对数组排序 
	int x=0,y=0,z=0;		//用来判断是否排序完成 
	int Num;			//用来交换数字 
	while(1){
		
		//排序 
		for (i=0;i<ConNum;i++){
			if(AllNum[i]>AllNum[i+1]){
				Num=AllNum[i];
				AllNum[i]=AllNum[i+1];
				AllNum[i+1]=Num;
				//y=1说明排序还在继续
				y=1; 
			}
			//判断是否有相同数字 
			if(x==0 && AllNum[i]==AllNum[i+1]){
				n=AllNum[i];
				x=1;
			}
		}
		
		//如果排序仍在继续,说明没排完 
		if(y!=1){			
			break;
		}
		//y继续赋值0,继续排序 
		else{
			y=0;
		}
	}
	
	//找哪一个数字缺失 
	for (i=0;i<ConNum;i++){
		if(AllNum[i]==AllNum[i+1]-2){
			m=AllNum[i]+1;
		}
	}
	
	printf("%d %d",m,n);

	return 0;
}
2023/11/28 20:08
加载中...