π Day 18 β Teacher's Day Challenge | Bit++


ποΈ Date: August 11, 2025
π§© Platform: Codeforces
π’ Problems Solved Today: 1
π― Focus Topic: Strings, Conditional Statements
π Table of Contents
Daily Summary
π§© 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:
++
increasesx
by 1--
decreasesx
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
, orX--
).
π§Ύ 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, incrementx
.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
Metric | Value |
Problems Solved | 1 |
Topics Covered | Strings, Increment/Decrement |
Tools Used | C++ |
Next Focus | More String Processing & Simulation Problems |
Day | 18 / 43 |
π·οΈ Tags:#codeforces #strings #cpp #beginner #dsa #43DaysChallenge
Subscribe to my newsletter
Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
