using namespace std;
ifstream is("date.in");
ofstream os("date.out");
int main()
{
int a[100],sp[100],n,s;
is>>n;
is>>a[0]; sp[0]=a[0];
for(int i=1;i<n;i++)
{
is>>a[i];
sp[i]=sp[i-1]+a[i];
}
is>>s;
for(int i=0;i<n;i++)
for(int j=i;j<n;j++)
if(sp[j]-sp[i-1]==s || (i==0 && sp[j]==s))
{ for(int k=i;k<=j;k++) os<<a[k]<<" ";
os<<"\n";
}
is.close();
os.close();
return 0;
}
sau
#include <fstream>
using namespace std;
ifstream is("date.in");
ofstream os("date.out");
int main()
{
int a[100],sp[100],n,s;
is>>n;
sp[0]=0;
for(int i=1;i<=n;i++)
{
is>>a[i];
sp[i]=sp[i-1]+a[i];
}
is>>s;
for(int i=1;i<n;i++)
for(int j=i;j<=n;j++)
if(sp[j]-sp[i-1]==s)
{ for(int k=i;k<=j;k++) os<<a[k]<<" ";
os<<"\n";
}
is.close();
os.close();
return 0;
}
|