algorithm
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int x =1, y =-2;
cout <<max(x,y)<< " "<< min(x,y)<<endl;
cout << abs(x)<<" "<<abs(y)<<endl;
return 0;
} */
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int x=1, y=2, z;
swap(x, y);
cout<< x << " "<< y<<endl;
swap(x, z);
cout<<x<< z <<endl;
swap(y, z);
cout<<y<< z <<endl;
return 0;
}
*/
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int a[10]= {
10, 11, 12, 13, 14, 15};
reverse(a, a+4);
for(int i=0; i<6; i++){
cout<<a[i]<<" ";
}
return 0;
}*/
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str = "abcdefghi";
reverse(str.begin()+2, str.begin()+6);
for( int i=0; i < str.length(); i++){
cout<<str[i]<<" ";
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int a[10] = {
3, 2, 1};
do{
cout<<a[0]<< " "<<a[1]<<" "<<a[2]<<endl;
}while(next_permutation(a, a+3));
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int a[5] = {
1,2,3,4,5};
fill( a, a+5, 233);
for(int i=0;i<5;i++){
cout<<a[i]<<endl;
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int a[6] = {
9, 4, 2, 5, 6, -1};
sort(a, a+4);
for( int i = 0; i<6; i++){
cout<<*(a+i)<<" ";
}
cout<<" "<<endl;
sort(a, a+6);
for( int i = 0; i<6; i++){
cout<<*(a+i)<<" ";
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int a[4] = {
3, 1, 4,2};
sort(a,a+4,cmp);
for(int i=0; i<4; i++){
cout<<*(a+i)<<" ";
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(char a, char b)
{
return a > b;
}
int main()
{
char a[4] = {
'a', 'b', 'c','d'};
sort(a,a+4,cmp);
for(int i=0; i<4; i++){
cout<<*(a+i)<<" ";
}
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int x, y;
}ssd[10];
bool cmp(node a,node b)
{
return a.x > b.x;
}
int main()
{
ssd[0].x =2;ssd[0].y=2;
ssd[1].x =1;ssd[1].y=3;
ssd[2].x =3;ssd[2].y=1;
sort(ssd, ssd+3, cmp);
for( int i=0; i<3; i++){
cout<< ssd[i].x <<endl;
}
cout<<" "<<endl;
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[10]={
1,2,2,3,3,3,5,5,5,5};
int* lowerPos = lower_bound(a, a+10, -1);
int* upperPos = upper_bound(a, a+10, -1);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
lowerPos = lower_bound(a, a+10, 1);
upperPos = upper_bound(a, a+10, 1);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
lowerPos = lower_bound(a, a+10, 2);
upperPos = upper_bound(a, a+10, 2);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
lowerPos = lower_bound(a, a+10, 3);
upperPos = upper_bound(a, a+10, 3);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
lowerPos = lower_bound(a, a+10, 4);
upperPos = upper_bound(a, a+10, 4);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
lowerPos = lower_bound(a, a+10, 6);
upperPos = upper_bound(a, a+10, 6);
cout<<lowerPos-a<< " "<<upperPos-a<< endl;
return 0;
}