304 North Cardinal St.
Dorchester Center, MA 02124

# Split The String CodeChef Solution

## Split The String CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
int t;cin>>t;
while(t--){
int a,b;cin>>a>>b;
string s;cin>>s;
int c0=0,c1=0;
for(int i=0;i<a;i++){
if(s[i]=='0')c0++;else c1++;
}//cout<<c0<<"**"<<c1<<"\n";
int k=abs(c1-c0);
/*if(c1==c0)cout<<0;
else if(k%2==0)cout<<2;else*/
int z=k/b;
if(k%b!=0)z+=1;
cout<<z;cout<<"\n";
}
return 0;
}

## Split The String CodeChef Solution in C++14

#include <bits/stdc++.h>
using namespace std;

typedef long long int llt;

int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){

string s;
llt n, k;
cin>>n>>k>>s;
int z = 0, o = 0;
for(char c : s){
if(c == '1') o++;
else z++;
}
llt mn = min(o,z);
o -= mn;
z -= mn;
llt ans = max(o,z);
if(ans%k == 0) cout<<ans/k<<"\n";
else cout<<(ans/k + 1)<<"\n";

}
return 0;
}

## Split The String CodeChef Solution in PYTH 3

import math
t = int(input())

for i in range(t):
n,k = map(int,input().split())
s = input()
o = 0
z = 0
for i in s:
if i=='0':
z += 1
else:
o += 1
l = abs(z-o)
m = (int)(math.ceil(l/k))

print(m)

## Split The String CodeChef Solution in C

#include<stdio.h>
#include <math.h>

int main(){
int t;
scanf("%d", &t);
while(t--){
int n, k, r1, r2;
scanf("%d %d", &n, &k);
char d[n];
scanf("%s",d);
int c1=0,c2=0;
for(int i=0;i<n;i++){
if(d[i]=='1') c1++;
else c2++;
}
r1=abs(c1-c2);
r2=(r1/k);
if(r1%k==0){
printf("%d\n",r1/k);}
else{
printf("%d\n",r2+1);
}
}
return 0;
}

## Split The String CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int k = sc.nextInt();sc.nextLine();
int ans = 0;
char[] c = sc.nextLine().toCharArray();
for(int i = 0; i < n; i++){
if(c[i] == '1')
ans++;
else
ans--;
}
if( ans < 0)
ans=ans*(-1);
int min = ans/k;
if(ans%k != 0)
min++;
System.out.println(min);
}
}
}

## Split The String CodeChef Solution in PYPY 3

for _ in range(int(input())):
n,k=map(int,input().split())
s=input()
ones=s.count('1')
zeros=s.count('0')
d=abs(ones-zeros)
x=d//k+(1 if d%k!=0 else 0)
print(x)

## Split The String CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
st = raw_input().split()
N = int(st[0])
K = int(st[1])
st = raw_input().strip()
c = 0
for x in st:
if x == '0':
c += 1
# endif
# endfor x
b = abs(N-2*c)
r = b/K
if b%K > 0:
r += 1
# endif
print r
# endfor i

## Split The String CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Test
{
//private static int limit = 65536;//(int)Math.Pow(2, 14);
//Console.WriteLine(limit);
//private static int[,] xors = new int[limit, limit];
public static void Main()
{
var inputStr = string.Empty;
//for(int i = 0; i < noOfTestCases; i++)
while(noOfTestCases-- > 0)
{
var inputData = inputStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => int.Parse(x)).ToArray();
SplitString(inputData[0], inputData[1], inputStr);
}
}

private static void SplitString(int N, int K, string inputStr)
{
var chars = inputStr.ToCharArray();
int count0 = 0;
int count1 = 0;
for(int i = 0; i < N; i++)
{
if(chars[i] == '1')
count1++;
else
count0++;
}
int badScore = Math.Abs(count0 - count1);
{
return;
}
//{
//    Console.WriteLine(1);
//    return;
//}

int ans = badScore / K;
//Console.WriteLine(badScore + " " + K + " " + ans);
ans++;
Console.WriteLine(ans);

}

private static int[] GetInputLineValues(int N)
{
Console.WriteLine(N);
var inputData = new List<int>();
var stringInp = string.Empty;
for(int i = 0; i < N; i++)
{
if(stringInp != string.Empty)
{
}
stringInp = string.Empty;
}

return inputData.ToArray();
}

private static string[] GetInputLineValuesAsStrings(int N)
{
//Console.WriteLine(N);
var inputData = new List<string>();
var stringInp = string.Empty;
for(int i = 0; i < N; i++)
{
if(stringInp != string.Empty)
{
}
stringInp = string.Empty;
}

return inputData.ToArray();
}
}

## Split The String CodeChef Solution in GO

package main

import (
"bufio"
"bytes"
"fmt"
"os"
)

func main() {
// hint(105)

var buf bytes.Buffer

for tc > 0 {
tc--
res := solve(s, k)
buf.WriteString(fmt.Sprintf("%d\n", res))
}

fmt.Print(buf.String())
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func solve(s string, k int) int {
cnt := make([]int, 2)
n := len(s)

for i := 0; i < n; i++ {
cnt[int(s[i]-'0')]++
}
if cnt[0] > cnt[1] {
cnt[0], cnt[1] = cnt[1], cnt[0]
}

res := cnt[1] - cnt[0]
// to decrease res,

return (res + k - 1) / k
}
##### Split The String CodeChef Solution Review:

In our experience, we suggest you solve this Split The String CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Split The String CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Split The String CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!