| 
 | 
back to boardthis one prefer "double" rather than "float" Posted by  Feng 10 Apr 2009 12:06 accept this kind of double: #include <vector> #include <iostream> #include <algorithm> #include <iterator>   #include <cmath>   using namespace std;   void root( double& d ) {     d = sqrt(d); }   int main() {     vector<double> arr;     copy( istream_iterator<double>(cin), istream_iterator<double>(), back_inserter(arr) );       for_each( arr.begin(), arr.end(), root );       cout.precision(4);     cout << fixed;     copy( arr.rbegin(), arr.rend(), ostream_iterator<double>(cout, "\n"));       return 0; }   Wrong answer of "float" type:   #include <vector> #include <iostream> #include <algorithm> #include <iterator>   #include <cmath>   using namespace std;   void root( float& d ) {     d = sqrt(d); }   int main() {     vector<float> arr;     copy( istream_iterator<float>(cin), istream_iterator<float>(), back_inserter(arr) );       for_each( arr.begin(), arr.end(), root );       cout.precision(4);     cout << fixed;     copy( arr.rbegin(), arr.rend(), ostream_iterator<float>(cout, "\n"));       return 0; }   strange problem ......  |  
  | 
|