#include
#include
#include
using namespace std;
class Predicate{
private:
int count=0;
public:
bool operator()(int data){
if ( count>=3 ) return false;
else{
bool x=(data<=20 && data%3==0);
count+=x;
// cout< vec{2,4,5,6,10,15,3,21,36,72,9,13};
vector result;
result.resize (vec.size());
// auto end=copy_if(vec.begin (),vec.end (),result.begin(),predicate);
int count=0;
auto end=copy_if(vec.begin (),vec.end (),result.begin()
,[&count](int data)->bool{
if ( count>=3 ) return false;
else{
bool x=(data<=20 && data%3==0);
count+=x;return x;
}
}
);
result.erase(end,result.end ());
for_each(result.begin (),result.end (),[](int e){cout<
6
15
3
[Finished in 0.4s]
#include
#include
#include
Test2:
Welcome to the Student Management System!
But can I must say the our teacher has less creativity in teaching...
In two continuous semeters this project always is the hardest task...
I only look foward there will be some intersting task in the 14-15th week.
#include
using namespace std;
int main(){
map count;//save as pair
string word;
int n;cin>>n;
while(n--) {
cin>>word;
++count[word];
}
for(auto e:count){//what inside map ??????
cout<
看情况
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace std::placeholders;
int main(){
auto divd=[](auto x,auto y){return x/y;};
auto dint=bind(divd,_1,_2);
auto rddou=bind(divd,_2,_1);
cout<
include
using namespace std;
int main(){
enum week{Monday,Tuesday,Wednesday};
week a=Monday;
a=(week)1;
cout<<&a<
0x7ffee452bb3c
1
1
[Finished in 0.4s]
#include
#include
#include
#include
#include
using namespace std;
void myfunction (int i)
{
cout << " " << i;
}
struct myclass
{
void operator() (int i)
{
cout << " " << i;
}
} myobject;
class MeanVlaue
{
public:
MeanVlaue():num(0),sum(0){}
void operator() (int elem)
{
num++;
sum+=elem;
}
double value()
{
return static_cast(sum)/static_cast(num);
}
operator double()//重载的好处,简洁!
{
return static_cast(sum)/static_cast(num);
}
private:
long num;
long sum;
};
template
auto add(T1 &a)->decltype(a+10){
return a+=10;
}
template
class AddValue
{
public:
AddValue(const T& v):theValue(v){}
void operator() (T& elem)const
{
elem+=theValue;
}
private:
T theValue;
};
int main()
{
vector myvector;
myvector.push_back(10);
myvector.push_back(20);
myvector.push_back(30);
cout << "myvector contains:";
for_each (myvector.begin(), myvector.end(), myfunction);
// or:
cout << "\nmyvector contains:";
for_each (myvector.begin(), myvector.end(), myobject);
cout << endl;
MeanVlaue mv=for_each(myvector.begin(),myvector.end(),MeanVlaue());
cout<<"MeanValue:"<);//参数可以自己改,eg:*(myvector.begin())
for_each (myvector.begin(), myvector.end(), myobject);
cout << endl;
double mv2=for_each(myvector.begin(),myvector.end(),MeanVlaue());
cout<<"MeanValue:"<
myvector contains: 10 20 30
myvector contains: 10 20 30
MeanValue:20
20 30 40
MeanValue:30
[Finished in 0.4s]
```java
#include
#include
using namespace std;
template
T use_f(T x,function f){
static int count=0;
++count;
cout<<"count = "<(0.5,[](double u){return u*u;})<(0.5,Fp(0.5))<(0.5,dub)<
count = 1 &count = 0x10e73c260
0.25
count = 2 &count = 0x10e73c260
0.25
count = 3 &count = 0x10e73c260
0.25
[Finished in 0.5s]
#include
#include
#include
using namespace std;
#define all(x) x.begin(),x.end()
int main(){
vector vec1(10,10),vec2(10,11);
for_each(all(vec1),[](int x){cout<
10 10 10 10 10 10 10 10 10 10
0
1
100 100 100 100 100 100 100 100 100 100
2
3
1100 1100 1100 1100 1100 1100 1100 1100 1100 1100
4
[Finished in 0.4s]
#include
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
template
void out(T x){
cout< vec;
cout<);
cout< vec2(vec);
reverse(all(vec));
for_each(all(vec),out);
cout<);
cout<);
cout<
#include
#include
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
template
void out(T x){
cout< vec;
cout<);
cout< vec2(vec);
reverse(all(vec));
for_each(all(vec),out);
cout<);
cout<);
cout<