VladimirGekov

Untitled

Nov 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // Function to find string score
  2. int strScore(string str[], string s, int n)
  3. {
  4. int score = 0, index;
  5. for (int i = 0; i < n; i++) {
  6. if (str[i] == s) {
  7. for (int j = 0; j < s.length(); j++)
  8. score += s[j] - 'a' + 1;
  9. index = i + 1;
  10. break;
  11. }
  12. }
  13.  
  14. score = score * index;
  15. return score;
  16. }
  17.  
  18. // Driver code
  19. int main()
  20. {
  21. string str[] = { "sahil", "shashanak"
  22. , "sanjit", "abhinav", "mohit" };
  23. string s = "abhinav";
  24. int n = sizeof(str) / sizeof(str[0]);
  25. int score = strScore(str, s, n);
  26. cout << score << endl;
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment