⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4_9.cpp

📁 汽车加油问题
💻 CPP
字号:
#include"stdio.h"
void main()
{
	int i,m,n,t,p,k[100];//m表示汽车加满油的行驶距离,n表示汽车行驶路旅途中的加油站数目
	FILE *fp1,*fp2;
	if((fp1=fopen("input.txt","r"))==NULL)
	{
		printf("file cannot be opened\n");
		//exit(1);
	}
	fscanf(fp1,"%d %d",&m,&n);
	for(i=1;i<=n+1;i++)
		fscanf(fp1,"%d",&k[i]);
	if((fp2=fopen("output.txt","w"))==NULL)
	{
		printf("file cannot be opened\n");
		//exit(1);
	}
	/*fprintf(fp2,"%d-----%d\n",m,n);
	for(i=1;i<=n+1;i++)
		fprintf(fp2,"%d",k[i]);*/
	for(i=1;i<=n+1&&k[i]<=m;i++);
	if(i<n+2)
		fprintf(fp2,"No Solution");
	else
	{
		t=0;
		p=0;
		for(i=n+1;i>0;i--)
		{
			t=t+k[i];
			if(t>m)
			{
				p++;
				t=0;
				i++;
			}
		}
		fprintf(fp2,"%d",p);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -