Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 答案错误，错在何处？ （附代码）

Posted by qinghailake at 2009-08-04 18:01:14 on Problem 2371
```#include <iostream>
#include <string>

using namespace std;

template<typename T>
class sort
{
public:
void  static binary_insert_sort(T data[], const int n);

};

template<typename T>
void sort<T>::binary_insert_sort(T data[], const int n)
{
T key;
int i, j, low, high, m;
for (i=1; i<n; ++i)
{
key = data[i];
low = 0;
high = i - 1;
while (	low <= high)
{
m = (low + high) / 2;
if (key < data[m])
{
high = m - 1;
}
else
{
low = m + 1;
}
}
for (j=i-1; j>=high+1; --j)  // j>=high+1 ?
{
data[j+1] = data[j];
}
data[j+1] = key;
}
}

int main()
{

int n;
cin >> n; //5
int* data = new int[n];
for (int i=0; i<n; ++i)
{
cin >> data[i];
}

string str;
cin >> str;

int m;
cin >>m ;
int* idx = new int[m] ;
for (int i=0; i<m; ++i)
{
cin >> idx[i] ;
}

sort<int>::binary_insert_sort(data, 5);

for (int i=0; i<m; ++i)
{
cout << data[idx[i] - 1] << endl;
}

return 0;
}
```

Followed by: