#include <iostream>
#include <sstream>
#include<cmath>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
//許宇和
//undo not finish
//can't reset
//can't won
stringstream ss;
vector<string> split(string line){
vector<string> arr;
string word;
istringstream iss(line);
while (iss >> word) {
arr.push_back(word);
}
return arr;
}
bool isint(string s){
for(char ch:s){
if(!isdigit(ch)){
return false;
}
}
return true;
}
vector<int> cells;
vector<int> card;
string board[75];
vector<bool>check(false);
void print(vector<int>&vec){
for(int k=1;k<=vec.size();k++){
if(vec[k-1]>=10){
cout<<vec[k-1]<<" ";
}else{
cout<<" "<<vec[k-1]<<" ";
}
if(k%5==0){
cout<<endl;
}
}
cout<<endl;
}
void printboard(string *arr,int len){
cout<<endl;
for(int i=1;i<=len;i++){
cout<<arr[i-1];
if(i%3==0){
cout<<" ";
}
if(i%15==0){
cout<<endl;
}
}
}
void shuffle(vector<int> &arr){
int now =0;
for(int i=0;i<arr.size();i++){
card.push_back(arr[i]);
}
for(int a=0;a<card.size();a++){
int j=0;
j=(a + rand()%(card.size()-a));
now =card[a];
card[a]=card[j];
card[j] =now;
now =0;
}
print(card);
}
int checkh(string *arr,int len){
//找橫線
int size =len/3;
int count =sqrt(size),line =0;
for(int i=0;i<count*5;i+=5){
//cout<<"line begin i: "<<i<<" arr[i*3+2]: "<<arr[i*3+2]<<endl;
if(arr[i*3+2]!="*"){
continue;
}else{
//cout<<"i: "<<i<<endl;
for(int j=1;j<count;j++){
//cout<<"arr[(i+j)*3+2]: "<<arr[i+j*3+2]<<endl;
if(arr[(i+j)*3+2]!="*"){
//cout<<"J not *: "<<j<<" "<<"i+j*3+2: "<<i+j*3+2<<"line: "<<line<<endl;
break;
}else if(j==count-1){
line++;
//cout<<j<<" "<<line<<endl;
}
}
}
}
return line;
}
int checkv(string *arr,int len){
//找直線
int size =len/3;
int count =sqrt(size),line =0;
for(int i=0;i<count;i++){
//cout<<"line begin i: "<<i<<" arr[i*3+2]: "<<arr[i*3+2]<<endl;
if(arr[i*3+2]!="*"){
continue;
}else{
//cout<<"i: "<<i<<endl;
for(int j=5;j<count*5;j+=5){
//cout<<"arr[(i+j)*3+2]: "<<arr[i+j*3+2]<<endl;
if(arr[(i+j)*3+2]!="*"){
//cout<<"in"<<" ";
//cout<<"J not *: "<<j<<" "<<"i+j*3+2: "<<i+j*3+2<<"line: "<<line<<endl;
break;
}else if(j==5*(count-1)){
line++;
//cout<<j<<" "<<line<<endl;
}
}
}
}
return line;
}
int checkd(string *arr,int len){
//找斜線
int size =len/3;
int count =sqrt(size),line =0;
for(int i=0;i<=count*6;i+=6){
//cout<<"line begin i: "<<i<<" arr[i*3+2]: "<<arr[i*3+2]<<endl;
if(arr[i*3+2]!="*"){
break;
}else{
if(i==6*(count-1)){
line++;
//cout<<j<<" "<<line<<endl;
}
}
}
for(int j=4;j<=count*4;j+=4){
//cout<<"line begin i: "<<i<<" arr[i*3+2]: "<<arr[i*3+2]<<endl;
if(arr[j*3+2]!="*"){
break;
}else{
if(j==4*(count-1)){
line++;
//cout<<j<<" "<<line<<endl;
}
}
}
return line;
}
void bingo1(){
//type?for help
//print welcome
//ss <<10;
//cout<<ss.str()[0];
//cout<<endl;
//cout<<ss.str()[1];
//cout<<endl;
cout<<"+----------------------------+"<<endl;
cout<<"| BINGO |"<<endl;
cout<<"| Game! |"<<endl;
cout<<"| made by Edward|"<<endl;
cout<<"+----------------------------+"<<endl;
cout<<"type?for help"<<endl;
cout<<"> ";
string line;
int step=0,lines=0,count =0, num=0,index= 0;
int hline=0,vline=0,dline=0;
while (getline(cin, line)) {
vector<string> words =split(line);
int len =words.size();
if(len==0){
cout<<"> ";
continue;
}
int line2=0;
string cmd =words[0];
if(cmd =="?"){
//print help
cout<<"How to play this game?"<<endl;
cout<<"input start to reset the bingo card"<<endl;
cout<<"input end to finish the game"<<endl;
cout<<"input'sel'+numbers to get lines"<<endl;
cout<<"You can play with your frineds,see who is the bingo king"<<endl;
cout<<"Have fun!"<<endl;
}else if(cmd =="start"){
//shuffle cells then print the table
cout<<"this is your bingo table"<<endl;
for(int i=1;i<=25;i++){
cells.push_back(i);
}
shuffle(cells);
for(int k=0;k<card.size();k++){
ss << card[k];
//string tmp;
//cout<<"SS"<<ss.str()<<" ";
//ss>>tmp;
//cout<<"tmp"<<tmp;
if(card[k]>=10){
board[k*3] =ss.str()[0];
board[k*3+1] =ss.str()[1];
board[k*3+2] =" ";
}else{
board[k*3] =" ";
board[k*3+1] =ss.str()[0];
board[k*3+2] =" ";
}
ss.str("");
//cout<<"finsh";
//cout<<board[k]<<board[k+1]<<board[k+2];//cout<<endl;
}
//printboard(board,75);
}else if(cmd =="exit"){
//stop the game
cout<<"bye"<<endl;
break;
}else if(cmd =="sel"){
//cout<<"enter"<<endl;
//check numbers
step++;
//cout<<words[1]<<endl;
if(isint(words[1])==true){
num =stoi(words[1]);
//cout<<num<<endl;
for(int i=0;i<card.size();i++){
//cout<<card[i]<<endl;
if(num ==card[i]){
index=i;
//cout<<i<<endl;
//count=9;
//print();
board[i*3+2] ="*";
}
//cout<<board[k]<<" "<<board[k+1]<<" "<<board[k+2]<<" ";
}
printboard(board,75);
cout<<"--------------------"<<endl;
hline =checkh(board,75);
vline =checkv(board,75);
dline =checkd(board,75);
line2 =hline+vline+dline;
cout<<"step: "<<step<<" "<<"lines: "<<line2<<endl;
if(line2==5){
cout<<"you won!"<<endl;
break;
}
//cout<<"hline: "<< hline<<" ";
// cout<<"vline: "<< vline<<" ";
//cout<<"dline: "<< dline<<" ";
}
}else if(cmd=="undo"){
//cout<<"undo"<<" "<<index<<" ";
step--;
board[index*3+2] =" ";
printboard(board,75);
cout<<"--------------------"<<endl;
cout<<"step: "<<step<<" "<<"lines: "<<line2<<endl;
}else{
cout<<"unkuown"<<endl;
}
cout<<"> ";
}
}
void game6(){
cout<<"[]"<<endl;
string line;
vector<int> newline;
int total =0,x=0;
while (getline(cin, line)) {
vector<string> words =split(line);
if(words[0]=="add"){
if(newline.size() ==1){
cout<<"invalid"<<endl;
}else{
total=newline[1]+newline[0];
newline.clear();
newline.push_back(total);
total=0;
}
}else if(words[0] == "push"){
for(int i=1;i<words.size();i++){
newline.push_back(stoi(words[i]));
}
}else if(words[0]=="times"){
total=newline[1]*newline[0];
newline.clear();
newline.push_back(total);
total=0;
}else if(words[0]=="sub"){
if(newline.size() ==0){
cout<<"invalid"<<endl;
}else{
total=newline[newline.size()-1]-stoi(words[words.size()-1]);
newline[newline.size()-1] =total;
total=0;
}
}else if(words[0]=="exit"){
x=2;
cout<<"bye"<<endl;
break;
}else{
cout<<"unknown "<<words[0]<<endl;
}
if(x!=2){
cout<<"[";
for(int a=0;a<newline.size();a++){
if(a!=newline.size()-1){
cout<<newline[a]<<",";
}else{
cout<<newline[newline.size()-1];
}
x=1;
}
cout<<"]";
if(x==1){
cout<<endl;
x=0;
}
}
}
}
void game5(){
cout<<"value: 0"<<endl;
string line;
int x=0;
int count =0;
int total =0;
while (getline(cin, line)) {
vector<string> words =split(line);
bool good =true;
if(words[0]=="add"){
for(int i=1;i<words.size();i++){
if(isint(words[i])==false){
for(int j=1;j<=count;j++){
total-=stoi(words[j]);
}
x=1;
count =0;
break;
}else{
total+=stoi(words[i]);
count++;
}
}
}else if(words[0] == "sub"){
for(int i=1;i<words.size();i++){
if(isint(words[i])==false){
for(int j=1;j<=count;j++){
total+=stoi(words[j]);
}
x=1;
count =0;
break;
}else{
total-=stoi(words[i]);
}
}
}else if(words[0]=="times"){
for(int i=1;i<words.size();i++){
if(isint(words[i])==false){
for(int j=1;j<=count;j++){
total/=stoi(words[j]);
}
x=1;
count =0;
break;
}else{
total*=stoi(words[i]);
}
}
}else if(words[0]=="exit"){
cout<<"bye"<<endl;
x=9;
break;
}else{
cout<<"unknown op "<<words[0]<<endl;
}
count=0;
if(x==1){
cout<<"invalid number"<<endl;
x=0;
count =0;
}
cout<<"value: "<<total<<endl;
}
}
void game4(){
string line;
while (getline(cin, line)) {
int sum =0;
vector<string> words =split(line);
bool good =true;
for(string word:words){
if(isint(word)==true){
sum+=stoi(word);
}else{
good =false;
break;
}
}
if(good){
cout<<sum<<endl;
}else{
cout<<"invalid"<<endl;
}
}
}
void game3(){
string line;
while (getline(cin, line)) {
int sum =0;
vector<string> words =split(line);
for(string word:words){
sum+=stoi(word);
}
cout<<sum<<endl;
}
}
void game2(){
int nlines = 0;
string line, word;
while (getline(cin, line)) {
++nlines;
vector<string> words =split(line);
cout<<"L"<<nlines<<": ";
for(int i=0;i<words.size();i++){
cout<<i+1<<". "<<words[i]<<" ";
}
cout<<endl;
}
}
void game1(){
int nlines = 0;
string line, word;
while (getline(cin, line)) {
++nlines;
cout<<"L"<< nlines<<": ";
istringstream iss(line);
int i=1;
while (iss >> word) {
cout <<i<<". " << word<<" ";
i++;
}
cout<<endl;
}
}
int main() {
srand(time(NULL));
//game1();
//game2();
//game3();
//game4();
//game5();
//game6();
bingo1();
}
/* (1) game1, game2
input:
Stone Campus
Campus Coding Stone Good
Programming Campus
Best Campus Best
output:
L1: 1. Stone 2. Campus
L2: 1. Campus 2. Coding 3. Stone 4. Good
L3: 1. Programming 2. Campus
L4: 1. Best 2. Campus 3. Best
(2) game3 - use split()
input:
100 200
10 20 30
123
output:
300
60
123
(3) game4 - use split()
input:
100 200
10 20a 30
10 20 3a0
123
output:
300
invalid
invalid
123
(4) game5 - use split(), isint()
input:
add 100 200
sub 10 20 30
add 1 20a
suB 10
times 10
exit
output:
value: 0
value: 300
value: 240
invalid number
value: 240
unknown op suB
value: 240
value: 2400
bye
(4) game6 - use split(), vector.push_back(), pop_back(), back()
input:
push 10 20
add
push 100
sub 1
Add
add
add
push 10
times
exit
output:
[]
[10, 20]
[30]
[30, 100]
[30, 99]
unknown Add
[30, 99]
[129]
invalid
[129]
[129, 10]
[1290]
bye
(5) bingo1: shuffle(vector<int> &arr)
input:
?
start
start
exit
output:
+-------------------+
| Bingo!! |
| by jy |
+-------------------+
(type ? for help)
> ?
bingo commands:
start - start game
exit - exit game
> start
1 3 5 7 9
2 4 6 8 10
11 13 15 17 19
12 14 16 18 20
21 22 23 24 25
> start
11 13 15 17 19
12 14 16 18 20
1 3 5 7 9
2 4 6 8 10
21 22 23 24 25
> exit
bye
(6) bingo2: shuffle(vector<int> &arr), isint()
input:
?
start
sel 1
...
exit
output:
+-------------------+
| Bingo!! |
| by jy |
+-------------------+
(type ? for help)
> ?
bingo commands:
start - start game
sel <n> - choose n
exit - exit game
> start
3 1 5 7 9
2 4 6 8 10
11 13 15 17 19
12 14 16 18 20
21 22 23 24 25
--------------------
step: 0 lines: 0
> sel 3
3* 1 5 7 9
2 4 6 8 10
11 13 15 17 19
12 14 16 18 20
21 22 23 24 25
--------------------
step: 1 lines: 0
> sel 4
3* 1 5 7 9
2 4* 6 8 10
11 13 15 17 19
12 14 16 18 20
21 22 23 24 25
--------------------
step: 2 lines: 0
....
> sel 25
3* 1 5 7 9
2 4* 6 8 10
11 13 15* 17 19
12 14 16 18* 20
21 22 23 24 25*
--------------------
step: 5 lines: 1
....
> sel 24
3* 1* 5* 7* 9*
2* 4* 6* 8* 10*
11 13 15* 17* 19*
12 14 16 18* 20*
21 22 23 24* 25*
--------------------
step: 17 lines: 5
YOU WON!
> exit
bye
(7) bingo3:
多一個 undo 指令,倒回一步
*/