Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function to find string score
- int strScore(string str[], string s, int n)
- {
- int score = 0, index;
- for (int i = 0; i < n; i++) {
- if (str[i] == s) {
- for (int j = 0; j < s.length(); j++)
- score += s[j] - 'a' + 1;
- index = i + 1;
- break;
- }
- }
- score = score * index;
- return score;
- }
- // Driver code
- int main()
- {
- string str[] = { "sahil", "shashanak"
- , "sanjit", "abhinav", "mohit" };
- string s = "abhinav";
- int n = sizeof(str) / sizeof(str[0]);
- int score = strScore(str, s, n);
- cout << score << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment