Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Magical Doors codechef solution in c++

// solution<1> 
// Time 0.16 s
// memory 5.3 M
------------------------>>
#include<iostream>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

void solve()
{
	string ans;
	cin >> ans;
	ll count = 0;
	if (ans[0] == '0')
	{
		count++;
	}
	for (ll i = 1; i < ans.length(); i++)
	{
		if (ans[i] !=ans[i-1])
			count++;
	}
	cout << count << "
";
}

int main()
{

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}
-----------------------------------------------------------------------------------------
// solution<2> 
// Time 0.17 s
// memory 5.2 M
------------------------>>
#include<iostream>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

void solve()
{
	string ans;
	cin >> ans;
	ll count = 0;
	if (ans[0] == '0')
	{
		count++;
	}
	for (ll i = 0; i < ans.length()-1; i++)
	{
		if (ans[i] !=ans[i+1])
			count++;
	}
	cout << count << "
";
}

int main()
{

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: log like printf c++ 
Cpp :: operator using 
Cpp :: C++ concept simple requirements 
Cpp :: boundary traversal of binary tree 
Cpp :: Configuring an c++ OpenCV project with Cmake 
Cpp :: C++ Enumeration Type 
Cpp :: permutation and combination program in c++ 
Cpp :: C++ 4.3.2 (gcc-4.3.2) sample 
Cpp :: e.cpp 
Cpp :: cicli informatica c++ 
Cpp :: void does not a name a type in cpp 
Cpp :: c++ login 
Cpp :: online computer graphics compiler c++ 
Cpp :: opengl triangle example 
Cpp :: random c++ 
Cpp :: fenwick tree 
Cpp :: cpp queue 
Cpp :: how to replace an element in array in c++ 
Cpp :: frequency of characters in a string in c++ 
Cpp :: c++ influenced 
C :: csrf_exempt 
C :: How to install npm in alpine linux 
C :: sstf program in c 
C :: execution time of c program 
C :: how to convert string to integer in c 
C :: c format specifiers 
C :: how to ban websites on mac 
C :: how to empty string in c 
C :: c check if char is an operator 
C :: c language time() function 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =