Question-
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
Operation ++ increases the value of variable x by 1.
Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x.
The statement is written without spaces, that is, it can only contain characters "+", "-", "X".
Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed.
Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Explanation-
1)The first input will be of the number inputs user will give in the form of ++X,X++,X-- or --X.
2)So create an empty string which will take input ++X,X++,X-- or --X.
3)Create another four different strings which will have these bits in it.
4)Loop will be for taking the input by user one after the another as these bits.
5)So when the user input string will match our predefined string, then print the required output.
6)++X or X++ will increment the value of 'x' by one and X-- or --X will decrement the value of 'x' by one. Default value of 'x' is 0.
Program-
Link to problem on Codeforces-https://codeforces.com/problemset/problem/282/A
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
Operation ++ increases the value of variable x by 1.
Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x.
The statement is written without spaces, that is, it can only contain characters "+", "-", "X".
Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed.
Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Explanation-
1)The first input will be of the number inputs user will give in the form of ++X,X++,X-- or --X.
2)So create an empty string which will take input ++X,X++,X-- or --X.
3)Create another four different strings which will have these bits in it.
4)Loop will be for taking the input by user one after the another as these bits.
5)So when the user input string will match our predefined string, then print the required output.
6)++X or X++ will increment the value of 'x' by one and X-- or --X will decrement the value of 'x' by one. Default value of 'x' is 0.
Program-
#include<iostream> using namespace std; int main() { int n; cin>>n; int x=0; string s1; string s2("++X"); string s3("X++"); string s4("--X"); string s5("X--"); for(int i=0;i<n;i++) { cin>>s1; if(s1==s2||s1==s3) x=x+1; else x=x-1; } cout<<x;}
Link to problem on Codeforces-https://codeforces.com/problemset/problem/282/A
Thank you...Keep it up
ReplyDeletethnkx for ur appreciation more solutions will be uploaded,keep supporting
DeleteThank you
ReplyDeleteVery good keep uploading more
ReplyDelete