int i = 0, j = 8;
while (++i<5)
cout << i << ':' << j-- << endl;
Copyright By PowCoder代写 加微信 powcoder
When we use i++ i is incremented, but the old value is used in any enclosing expression
When we use ++i, the new value is used
int a[] = { 3, 2, 1, 0, 4 }, b[5];
for (int i=0; i<5; i++)
{ if (!(b[i] = a[i])) break; // =, not ==
cout << b[i] << endl;
a 3 2 1 0 4
b 3 2 1 0 ?
map
marks.insert(make_pair(“Mike”, 75.5));
marks.insert(make_pair(“Homer”, 45.7));
marks[“Ned”] = 12.5;
makrs[“Lisa”] = 99.9;
map
for (it = marks.begin(); it->second>20; it++)
cout << it->first << ' ' << it->second << end;
it x
marks Homer:45.7 Lisa:99.9 Mike: 75.5 Ned:12.5
Homer 45.7
vector
v.push_back(7);
v.push_back(3);
v.push_back(4);
v.push_back(5);
sort(v.begin(), –v.end());
cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' v[3] << endl;
v.begin() --v.end()
v 3 4 7 5
list
ll.push_back(5);
ll.push_front(2);
ll.push_back(3);
list
for (it = ll.rbegin(); it!=ll.rend(); it++)
cout << *it << ' ';
cout << endl;
ll 2 5 3
priority_queue
pq.push(3.1);
pq.push(5.3)’
cout << pq.top() << endll
pq.push(4.2);
cout << pq.top() << endl;
pq contents 3.1 4.2
int i = 5, j = 0; a = {1, 2, 3, 4, 5, 6};
while (i>2)
cout << a[i--] << ';' << a[++j] << endl;
int i = 4;
while (i != 0)
{ if (i%2==0) i += 3;
else i = i>>1;
cout << i << endl;
bool b1 = 0, b2 = -10;
cout << b1 << ':' << b2 << endl;
false:true
vector
v.push_back(5);
v.push_back(3);
v.push_back(9);
sort(v.rbegin(), v.rend())
cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
v 9 5 3
list
ll.push_front(1);
ll.push_back(2);
ll.push_front(4);
list
for (it = ll.rbegin(); it!=ll.rend(); it++)
cout << *it << ' ';
cout << endl;
ll 4 1 2
map
age.insert(make_pair(“Mike”, 10));
age[“Bart”] = 15;
age[“Lisa”] = 12;
age[“Marge”] = 25;
map
for (it = age.begin(); it->second<20; it++)
cout << it->first << ' ' << it->second << endl;
it Bart:15 Lisa:12 Marge:25 Mike:10
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com