JavaScript D8 gives undefined
for this code.
const a = readline()
console.log(a)
JavaScript D8 gives undefined
for this code.
const a = readline()
console.log(a)
This is an issue with D8 itself. If the line doesn’t end with \r\n
, readline returns undefined
But this works for me in NodeJS
let _inputData="",_inputArray=[],_count=-1;function input(){let n=_inputArray[_count];return _count++,n}process.stdin.setEncoding("utf8"),process.stdin.on("data",(function(n){_inputData+=n})),process.stdin.on("end",(function(){_inputArray=_inputData.split("\n"),input(),main()}));
function main() {
let a = input();
console.log(a);
}
It’s a bunch of code for just taking input. But comparing to C++, it’s not much.
In C++, you have to much more things than this.
So, until a workaround comes for this problem in D8, we have nothing to do except changing the Test Cases ending to \r\n
.
@Kuddus.6068 There was an issue with the test cases. None of the input files ended with line feeds. Like @Nusab19 said, D8 is very particular about how the input is laid out.
#include <stdio.h>
#include<math.h>
int main() {
int n;
scanf(“%d”,&n);
int i;
int a=1;
for(i=n;i>=1;i–){
a=ai;
}
int d=a;
int c=0;
while(d!=0){
d=d/10;
c++;
}
if(c<4) printf(“%d\n”,a);
else if(c>=4)
{
int e=0;
int m;
int sum=0;
while(e<4)
{
m=a%10;
a=a/10;
e++;
sum+=m(int)pow(10,e-1);
}
printf("%d",sum);
}
return 0;
}
what’s wrong with this?
#include<stdio.h>
int main()
{
//used long long due to the result of factorials being very high, trillion +
long long N;//integer N
long long factorial, last4, i;
long long a = 1; //start of the factorial
scanf("%lld", & N);
for(i = 1; i<N; i++)//Factorial loop
{
factorial = a * (i+1);
a = factorial;
}
if(factorial>=1000)//must be 4digits or more.
{
last4 = factorial % 10000;//last four digits
printf("%04lld", last4);
}
else//for those that aren't 4 digits or more long
{
printf("%lld", factorial);//first four=last four
}
return 0;
}
Can someone help me in finding the error in this code?
This happens when I input my code.
Please help.
EDIT: I have figuired it out, THANKS. !!
@clement1raka Test your code with an input like:
55
Thank you, i have figuired it out.
for i in range(1,N):
if N-i>=1:
N_=N_*(N-i)
ans=str(N_)
g= len(ans)
if g>=4:
print(int(ans[g-4]+ans[g-3]+ans[g-2]+ans[g-1]))
elif g==3:
print(int(ans[g-3]+ans[g-2]+ans[g-1]))
elif g==2:
print(int(ans[g-2]+ans[g-1]))
elif g==1:
print(int(ans[g-1]))
what’s the problem here ?