@Kuzia domovenok
2122 / 1952 / 193
Регистрация: 25.03.2012
Сообщений: 6,772
|
19.07.2013, 16:24
|
|

Сообщение от Jupiter
std::advance
спасибо, тогда C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| #include <iostream>
#include <ctime>
#include <list>
using namespace std;
const char* sides_names[]={"PLR", "CPU"};
const int PLAYER=0;
const int CPU=1;
const int SIZE=10;
struct tplayer{
int side;
int id;
};
list<tplayer> players;
int main(){
srand(time(NULL));
list<tplayer>::iterator it;
tplayer new_player
new_player.id=1;
for(new_player.side=PLAYER; new_player.side<=CPU; new_player.side++)
for(int i=0; i<SIZE/2; i++){
int pos=rand()%(new_player.id);
it=players.begin();
advance(it, pos);
players.insert(it, new_player);
new_player.id++;
}
for (it=players.begin(); it!=players.end(); it++)
cout<<(it->id)<<" - "<<sides_names[it->side]<<endl;
return 0;
} |
|
0
|