adding cs235
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
CXXFLAGS= -Wall -g -std=c++0x
|
||||
OBJECTS= game.o
|
||||
EXE=main
|
||||
all: $(EXE)
|
||||
|
||||
$(EXE): $(OBJECTS)
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@
|
||||
game.o: game.cpp
|
||||
run: main
|
||||
./main
|
||||
|
||||
clean:
|
||||
@rm -vf *.o
|
||||
@rm -vf $(EXE)
|
||||
@rm -vf *.1
|
||||
@rm -vf *.0
|
||||
@rm -vf test
|
||||
@rm -rvf *.dSYM
|
||||
|
||||
drun: main
|
||||
gdb ./main
|
||||
|
||||
valgrind: $(EXE)
|
||||
valgrind --tool=memcheck --leak-check=yes ./$(EXE)
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<string> parse_expression(string expression) { //parses expression with " " being the delimeter
|
||||
vector<string> results;
|
||||
string s;
|
||||
for(unsigned int i = 0; i < expression.length(); i++) {
|
||||
char c = expression[i];
|
||||
if(c != ' ') {
|
||||
s += c;
|
||||
}
|
||||
else {
|
||||
if(s != "") {
|
||||
results.push_back(s);
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(s != "") {
|
||||
results.push_back(s);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
bool has_a(vector<string> list, string name) {
|
||||
for(unsigned int i = 0; i < list.size(); i++) {
|
||||
if(list[i] == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
srand(time(NULL));
|
||||
cout << "Please enter names with a space inbetween each player: ";
|
||||
string names;
|
||||
getline(cin, names);
|
||||
vector<string> list = parse_expression(names);
|
||||
vector<string> result;
|
||||
while(result.size() != list.size()) {
|
||||
int rand_m;
|
||||
while(rand_m != 50) {
|
||||
rand_m = rand() % 10000;
|
||||
}
|
||||
int rand_n = rand() % list.size();
|
||||
string adding = list[rand_n];
|
||||
if(!has_a(result, adding)) {
|
||||
result.push_back(adding);
|
||||
}
|
||||
}
|
||||
cout << "This is the order: " << endl;
|
||||
for(unsigned int i = 0; i < result.size(); i++) {
|
||||
cout << i + 1 << ") " << result[i] << endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user