All Tracks Algorithms String Algorithms Basics of String Manipulation Problem

47's Strings
Tag(s):
No tags
Problem
Editorial
Analytics

Diana sent a message "S" to agent 47 in an encrypted language so that no one else can decode it.

Now a string in encrypted language is said to be valid if and only if it contains the characters '$' or '&' . Agent 47 decided to count the number of valid sub-strings of the message "S" sent by Diana .

P.S. - '$' and '&' characters are considered as 4 -> '$' and 7 -> '&' in a key-board.

Can you help Agent 47 , in counting the total no. of valid substrings in encrypted message.

Note : Two sub-strings are different if they occur at different positions in the message.

Input :

  • First line consists of a single integer 'T' , i.e. no. of test cases .
  • Each test case consists of a string "S",i.e the message sent by Diana

Output :

  • For each test case, output a single integer containing the count of total no. of valid sub-strings in new line.

Constraints :

  • 1<=T<=10
  • 1<=|S|<=10^6
  • Message 'S' contains only lower case letters and characters '$' and '&'
SAMPLE INPUT
2
$bcd
flkjdh
SAMPLE OUTPUT
4
0
Explanation
  • Sample test 1: For the first case, there are 4 sub-strings containing '$' .
  • Sample test 2: There are no sub-strings having '$' or '&'.
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1, Swift, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

ABV- Indian Institute of Information Technology and Management, Gwalior

Challenge Name

CodeMaze v4.0

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?