πŸ“˜ Day 18 – Teacher's Day Challenge | Bit++

TanishiTanishi
2 min read

πŸ—“οΈ Date: August 11, 2025
🧩 Platform: Codeforces
πŸ”’ Problems Solved Today: 1
🎯 Focus Topic: Strings, Conditional Statements


πŸ”— Table of Contents


🧩 Problem 1 – Bit++

πŸ“š Difficulty: Easy-Medium
🧠 Concepts: Strings, Increment/Decrement Operations


πŸ“„ Problem Statement (Summary):
You are given n statements from the Bit++ programming language.
Each statement contains exactly one variable x and one operation:

  • ++ increases x by 1

  • -- decreases x by 1

Initially, x = 0.
Execute all statements in the given order and output the final value of x.


πŸ”’ Input Format:

  • First line: integer n (1 ≀ n ≀ 150) – number of statements.

  • Next n lines: each contains one statement (++X, X++, --X, or X--).

🧾 Output Format:
A single integer – the final value of x.

πŸ” Example 1:
Input:

1
++X

Output:

1

πŸ” Example 2:
Input:

2
X++
--X

Output:

0

πŸ’‘ Approach:

  • Start with x = 0.

  • For each statement:

    • If "++" is found in the string, increment x.

    • Otherwise, decrement x.

  • Output the final value of x.


πŸ§ͺ Code (C++):

#include <iostream>
using namespace std;

int main() {
    int n, X = 0;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s.find("++") != string::npos)
            X++;
        else
            X--;
    }
    cout << X;
    return 0;
}

πŸ“Έ Submission Screenshot:


βœ… Key Takeaways:

  • Detecting substrings with find() is a quick way to handle such pattern-based decisions.

  • Order of characters in the statement doesn’t matter for the result.

  • Initializing variables correctly at the start avoids logical errors.


πŸ“ˆ Daily Summary

MetricValue
Problems Solved1
Topics CoveredStrings, Increment/Decrement
Tools UsedC++
Next FocusMore String Processing & Simulation Problems
Day18 / 43

🏷️ Tags:
#codeforces #strings #cpp #beginner #dsa #43DaysChallenge

0
Subscribe to my newsletter

Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tanishi
Tanishi