hey thnx…my mistake i didn’t observe dat…thnx a lot…
Your class cannot be public
, that’s the first problem at CodeChef. In addition
int c = Integer.parseInt(t1.substring(n - 1, n));
c = c - 1;
You forgot to print number of open tweets after input “CLOSEALL”
I have added print statement and here’s the accepted version of your code
Thanks a lot!!
most welcome
I did it in a similar way and the answer is submitted
#include
#include
#include
#include
using namespace std;
int main ()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
std::string str;
std::bitset<1000> boo;
while(k–){
cin>>str;
if(str ==“CLOSEALL”){
boo.reset();
cout<<0<<"\n";
}
else{
int c;
cin>>c;
boo = boo.flip(1000-c);
cout<<boo.count();
cout<<endl;
}
}
return 0;
}
Can anyone help me out here? I’m getting wrong answer status. What’s wrong in my code?
https://www.codechef.com/viewsolution/25035176
you didn’t consider elements bigger than 9
your code will fail on those test cases
Thank you for pointing it out. It was kind of a silly mistake. Here’s the correct one.
https://www.codechef.com/viewsolution/25048355
This code is giving NZEC error Please help me
class TWTCLOSE {
int result = 0;
static int Program(String str, int val, int[] arr) {
if (arr[val] == 0) {
arr[val] = 1;
result++;
} else {
arr[val] = 0;
result--;
}
return result;
}
public static void main(String[] args) throws IOException {
java.io.BufferedReader r = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
int n = 0;
int k = 0;
n = r.read();
r.readLine();
k = r.read();
r.readLine();
int[] arr = new int[Character.getNumericValue(n)];
k = Character.getNumericValue(k);
if (n >= 1 && k <= 1000) {
while (k > 0) {
String str = r.readLine();
int length = str.length();
str.trim();
if (str.equalsIgnoreCase("closeAll")) {
System.out.println("0");
Arrays.fill(arr, 0);
result = 0;
} else {
int val = Integer.parseInt((str.substring(length - 1, length)));
System.out.println(Program(str, val-1, arr));
}
k--;
}
}
}
}
This is how I did it in Java.
class Codechef {
public static void main (String[]args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k = in.nextInt();
in.nextLine();
int ans=0;
int[] a = new int[n];
for (int i=0;i<k;i++)
{
String s=in.nextLine();
if (s.charAt(2)=='O')
{
ans=0;
a = new int[n];
}
else
{
int l=s.length();
String numstr=s.substring(6);
int num=Integer.parseInt(numstr);
if (a[num-1]==0)
{
a[num-1]=1;
ans++;
}
else
{
a[num-1]=0;
ans--;
}
}
System.out.println(ans);
}
}
}
x,t = map(int,input().split())
st=""
while(t):
s = input()
if(“ALL” in s):
st=""
else:
for i in range(1,x+1):
if(str(i) in s):
if(str(i) in st):
st = st.replace(str(i),"",1)
else:
st+=str(i)
# print(st)
print(len(st))
t-=1
what is wrong in this pls help me
Poor Noah no mention of him, his Twitter bio once read I created this ! it’s unfortunate how he faded into obscurity.
Here’s some more about him : Twitter's Forgotten Cofounder, Noah Glass
#include<bits/stdc++.h>
using namespace std;
int search(int a[],int i)
{
int x=0;
for(int j=0;j<i;j++)
{
if(a[i]==a[j])
x++;
}
return x;
}
int main()
{
int n,k,open=0;
cin>>n>>k;
string s;
int a[k];
for(int i=0;i<k;i++)
{
cin>>s;
int b;
if(s==“CLOSEALL”)
{
int j=0;
while(a[j])
{
a[j]=0;
j++;
}
open=0;
cout<<open<<endl;
}
else
{
cin>>a[i];
if(a[i]<=n)
{
b=search(a,i);
if(b%2==0)
open++;
else
open–;
cout<<open<<endl;
}
}
}
}
Why it is not being accepted as a correct answer?..
I am getting wrong answer for my code . can anyone check.
Solution : CodeChef: Practical coding for everyone
(k,n)=map(int,input().split())
str1=“”
count=0
for i in range(n):
l1=list(map(str,input().split(" “)))
if(l1[0]==“CLICK” and int(l1[1])<=n):
if l1[1] not in str1:
str1=str1+l1[1]
count=count+1
else:
str1.replace(l1[1],”“)
count=count-1
else:
str1=”"
count=0
print(str(count))
Consider the test input:
20 3
CLICK 1
CLICK 2
CLICK 12
Thank you
how you think for test cases it always happen with me i will be missing some test cases.
With this one - just spotted the flaw in your logic, and crafted a testcase to exploit it