In this HackerEarth The Dice problem solution There is x number of girls and they rolled dice in turns one after another. If the number on the dice is 6, then the dice will be rolled again until she gets a number other than 6.

Since you know the sequence of numbers which the dice show when rolled each time, you have to find what is the total number of girls or if the sequence is invalid.


HackerEarth The Dice problem solution


problem solution.

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

const int maxn = 1e5 + 20;

int main()
{
  string s;
  cin >> s;

  if(s.back() == '6')
    return cout << -1 << endl , 0;

  int res = s.size();
  for(auto ch : s)
    if(ch == '6')
      res--;

  cout << res << endl;
}


Second solution

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
const int maxn = 300100, maxv = 100, mod = 1e9 + 7, maxa = 1005, maxs = 820, maxb = 23, base = 737, base2 = 3079, mod3 = 1e7 + 19, delt = 10513;
const long long inf = 2e14;
const int infint = 1e9 + 11;
long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}



int32_t main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if(s[(int)(s.size()) - 1] == '6'){cout << -1 << endl; return 0;}
    int x = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != '6'){x++;}
    }
    cout << x << endl;
    return 0;
}