汽车加油问题.cpp

来自「汽车加油问题」· C++ 代码 · 共 44 行

CPP
44
字号
#include<iostream.h>
#include <fstream.h> // for operation on files
 ifstream fin("input.txt");
 ofstream fout("output.txt");
void main()
{
 int n, k;
 int s[1000];
 int i,t,l,tag=1;
 fin >> n >> k;
 for(i=0;i<=k;i++)
  fin >> s[i];
 l=n;
 t=0;
 for(i=0;i<=k;i++)
  if(s[i]<=n)
   if(s[i]>l)
   {
    l=n-s[i];
    t++;
   }
   else
    l=l-s[i];
  else
  {
	  cout<<"no solution"<<endl;
   fout<<"no solution"<<endl;
   tag=0;
   break;
  }
 //
 if(tag==1)
  fout << t << endl;
  cout << t << endl; 
 //

 // close the opened files
 fin.close();
 fout.close();

}


⌨️ 快捷键说明

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