中央論壇 - CENTER BBS
標題:
使用STL解題範列
[打印本頁]
作者:
f66666602
時間:
2007-8-14 04:39
標題:
使用STL解題範列
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std ;
int main() {
const int S = 5 ;
char correct[S] = { 'a' , 'p' , 'p' , 'l' , 'e' } ;
char wrong[S] = { 'e' , 'p' , 'a' , 'p' , 'l' } ;
int i ;
char *j , *k ;
copy( wrong , wrong+S , ostream_iterator<char>(cout," ") ) ;
for ( i = 0 ; i < S ; ++i ) {
j = find( wrong+i , wrong+S , correct ) ;
for ( k = j ; k > wrong+i ; --k ) {
swap( *k , *(k-1) ) ;
cout << " --> " ;
copy( wrong , wrong+S , ostream_iterator<char>(cout," ") ) ;
}
}
cout << endl ;
system("pause") ;
return 0 ;
}
複製代碼
歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/)
Powered by Discuz! X3