You are given a string, which contains entirely decimal digits (0-9). Each digit is made of a certain number of dashes, as shown in the image below. For instance, 1 is made of 2 dashes, 8 is made of 7 dashes, and so on.
You have to write a function that takes this string message as an input and returns a corresponding value in terms of a number. This number is the count of dashes in the string message.
Example:
Input: s = "12134"
Output: 18
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){map<char, int> mp;mp['1'] = 2;mp['2'] = 5;mp['3'] = 5;mp['4'] = 4;mp['5'] = 5;mp['6'] = 6;mp['7'] = 3;mp['8'] = 7;mp['9'] = 6;mp['0'] = 6;string s = "12134";int n = s.size();int ans = 0;for (int i = 0; i < n; i++)ans += mp[s[i]];cout << ans << "\n";return 0;}
No comments:
Post a Comment