Hello all,
Actually i had a program which i was unable to solve i hope youll help me out and post your solutions.
The program is:
A Bowler is called the Best, if the average wickets taken by him during the year is 5 and above. The number of matches played is calculated by the number of digits provided against a player. Assume that no bowler has taken 10 wickets in a match and the maximum number of matches played by one player is 100.write a program that calculates the count of best bowlers among the given lot.

Please do let me know.
Thanks.

Dani AI

Generated

Core idea (no floating point): each player's digits are wickets-per-match, so average >= 5 is equivalent to sum_of_digits >= 5 * number_of_matches. That lets the check be done with integers and avoids rounding pitfalls.

As and asked for runnable code, below is a compact, robust C++11 program. It handles two common input styles: (A) first token is an integer N followed by N player-strings, or (B) a list of player-strings until EOF. Non-digit tokens are ignored. Drop this into a file and compile with a modern g++/clang++.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

int main() {
    std::vector<std::string> tokens;
    std::string t;
    while (std::cin >> t) tokens.push_back(t);
    if (tokens.empty()) return 0;

    auto all_digits = [](const std::string &s) {
        if (s.empty()) return false;
        for (unsigned char ch : s) if (!std::isdigit(ch)) return false;
        return true;
    };

    bool firstIsCount = false;
    int n = 0;
    if (all_digits(tokens[0])) {
        try {
            n = std::stoi(tokens[0]);
            if (n >= 0 && (size_t)n + 1 == tokens.size()) firstIsCount = true;
        } catch (...) { firstIsCount = false; }
    }

    size_t start = firstIsCount ? 1 : 0;
    int best = 0;
    for (size_t i = start; i < tokens.size(); ++i) {
        const std::string &s = tokens[i];
        int sum = 0;
        bool ok = true;
        for (unsigned char ch : s) {
            if (!std::isdigit(ch)) { ok = false; break; }
            sum += ch - '0';
        }
        if (!ok) continue;
        if (sum >= 5 * (int)s.size()) ++best;
    }

    std::cout << best << '\n';
    return 0;
}

Notes and pitfalls: complexity is O(total digits). The program treats leading zeros as valid wickets (digit '0'). It skips tokens that contain non-digit characters (safer than crashing). Example: input
3 55555 55021 9999
produces output 2 (players 1 and 3 are "Best"). This should be a drop-in solution if did not have prior code to show.

Recommended Answers

All 2 Replies

If only life was so nice, but it doesn't work that way. You need to post how much code you have so far and then we will assist you from there. Be sure to put your code in code tags.

What have you done so far?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.