de pe pbinfo rafaelo(561)
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int main(){
int N, S, p, x, y, nr, pmin;
cin >> S >> N;
nr = 0;
pmin = 1000;
for (int i = 1;i <= N;i++) {
cin >> p;
nr++;
if (p < pmin) {
pmin = p;
y = nr;
x = S/p;
}
}
cout << x << " " << y;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int S, N, p, nmag, nmaxc, i, nc;
cin >> S >> N;
cin >> p; nmag=1; nmaxc=S/p;
for (i=2; i<=N; ++i)
{
cin >> p;
nc=S/p;
if (nc>nmaxc) { nmaxc=nc; nmag=i; }
}
cout << nmaxc << " " << nmag << endl;
return 0;
}
******************* 172 ***************
#include <iostream>
using namespace std;
int main()
{
int n, a, b,difmin, sumamin, i, dm, s, x, y;
cin >> n >> a >> b;
difmin=a-b; if (difmin<0) difmin*=-1;
sumamin=a+b; x=a; y=b; a=b;
for (i=3; i<=n; ++i)
{
cin >> b;
dm=a-b; if (dm<0) dm*=-1;
if (dm<difmin) { x=a; y=b; difmin=dm;}
else if (dm=difmin && a+b<sumamin) { x=a; y=b; sumamin=a+b; }
a=b;
}
cout << x << " " << y << endl;
return 0;
}