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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# include <iostream>
# include <cstring>
# include <cstdio>
using namespace std;
int getStrIndex(const char *);
float getResult(int,int);
int main()
{
char array[50];
string firstWord,secondWord;
cout << "Type your weapon -> ";gets(array);
char *ptr;
// Spliting those two words
ptr = strtok(array," ");
firstWord = ptr;
ptr = strtok(NULL," ");
secondWord = ptr;
int x = getStrIndex(firstWord.c_str());
int y = getStrIndex(secondWord.c_str());
if(x!=9&&y!=9)
{
cout << getResult(x,y);
}
return 0;
}
int getStrIndex(const char *ptr)
{
const char *szBuffer[] = {"Diamond","Iron","Ston","Gold","Wood"};
const char *szBuffer2[] = {"Sword","Axe","Pick","Shovel"};
for(int i=0;i<4;i++)
{
if(!strcmp(ptr,szBuffer[i])||!strcmp(szBuffer2[i],ptr))
return i;
}if(!strcmp(ptr,szBuffer[4]))return 3;
return 9;
}
float getResult(int x,int y)
{
float map[4][4] = {{3.5,3,2.5,2},
{3,2.5,2,1.5},
{2.5,2,1.5,1},
{2,1.5,1,0.5}};
return map[x][y];
}
|