-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram1.cpp
77 lines (73 loc) · 1.76 KB
/
Program1.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
#include<string.h>
using namespace std;
int compute_score(string);
int main()
{
int score1,score2;
string word1,word2;
cout<<"Player 1 \n Enter any word:";
cin>>word1;
cout<<"Player 2 \n Enter any word:";
cin>>word2;
score1=compute_score(word1);
score2=compute_score(word2);
cout<<"Score 1:"<<score1;
cout<<"\nScore 2:"<<score2;
if(score1>score2)
cout<<"\nPlayer 1 wins !\n";
else if(score1<score2)
cout<<"\nPlayer 2 wins !\n";
else cout<<"\nTie\n";
return 0;
}
int compute_score(string s)
{
int score=0,length;
int POINTS[7]={1,2,3,4,5,8,10};
char type1[20]={'a','A','E','e','I','i','L','l','N','n','O','o','R','r','S','s','T','t','U','u'};
char type2[8]={'B','b','C','c','M','m','P','p'};
char type3[4]={'D','d','G','g'};
char type4[8]={'F','f','H','h','V','v','W','w'};
char type5[4]={'J','j','X','x'};
char type6[4]={'Q','q','Z','z'};
length=s.length();
for(int i=0;i<length;i++)
{
for(int j=0;j<20;j++)
{
if(s[i]==type1[j])
score+=POINTS[0];
}
for(int j=0;j<8;j++)
{
if(s[i]==type2[j])
score+=POINTS[2];
}
for(int j=0;j<4;j++)
{
if(s[i]==type3[j])
score+=POINTS[1];
}
for(int j=0;j<8;j++)
{
if(s[i]==type4[j])
score+=POINTS[3];
}
for(int j=0;j<4;j++)
{
if(s[i]==type5[j])
score+=POINTS[5];
}
for(int j=0;j<4;j++)
{
if(s[i]==type6[j])
score+=POINTS[6];
}
if(s[i]=='K'||s[i]=='k')
score+=POINTS[4];
else
score+=0;
}
return score;
}