Problema #383 pbinfo explicata va rog in c++
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int i,n,k,v[201],w,d1,d2;
int main()
{
cin>>k>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
for(i=n;i>=1;i--)
{
if(v[i]%k==0) cout<<v[i]<<' ';
else
{
while(w<v[i])
{
w+=k;
}
d1=w-k;
if(v[i]-d1>w-v[i])
{
cout<<w<<' ';
}
else
{
cout<<d1<<' ';
}
w=0;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n,k,i,j,s,found=0;
cin>>k;
cin>>n;
int v[n];
for(i=0;i<n;i++)
cin>>v[i];
for(i=0;i<n;i++)
{
j=v[i];
s=v[i];
while(found==0)
{
if(j%k==0 || s%k==0)
{
if(j-v[i]==v[i]-s && s%k==0)
{
v[i]=s;
}
else
{
if(j%k==0)
v[i]=j;
else
if(s%k==0)
v[i]=s;
}
found=1;
}
j++;
s--;
}
found=0;
}
for(i=n-1;i>=0;i--)
cout<<v[i]<<" ";
}