#include<iostream>
using std::cin;
using std::cout;
int main()
{
int s;
cin >> s;
int a[30];
int i = 1;
for(auto p=std::begin(a);p!=std::end(a);++p)
{
*p = i;
++i;
}
int n = 0;
auto pp = std::begin(a);
auto dd = std::end(a);
while(s!=n)
{
int distance = (dd - pp) / 2;
auto min = pp + distance;
if (s == *min)n = *min;
if (s < *min)dd = min;
if (s > *min) pp = min;
using std::cin;
using std::cout;
int main()
{
int s;
cin >> s;
int a[30];
int i = 1;
for(auto p=std::begin(a);p!=std::end(a);++p)
{
*p = i;
++i;
}
int n = 0;
auto pp = std::begin(a);
auto dd = std::end(a);
while(s!=n)
{
int distance = (dd - pp) / 2;
auto min = pp + distance;
if (s == *min)n = *min;
if (s < *min)dd = min;
if (s > *min) pp = min;
}
cout << n;
return 0;
}
cout << n;
return 0;
}
456

被折叠的 条评论
为什么被折叠?



