i’m trying to submit this problem and with all the custom inputs its working fine but when i submit it shows wrong answer but why??
here is my code :
#include<bits\stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
int last=0,first=0;
last=n%10;
while(true){
n/=10;
if(n/10==0){
first=n;
break;
}
}
cout<<first+last<<"\n";
}
return 0;
}
ssjgz
2
FLOW004 Problem - CodeChef ? It gives the wrong answer for single digit numbers.
i tried it for single digit too but its still showing correct output
ssjgz
4
Not for me it isn’t:
[simon@simon-laptop][18:53:35]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh
Compiling black_jack002-FLOW004.cpp
Executing command:
g++ -std=c++17 black_jack002-FLOW004.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
black_jack002-FLOW004.cpp: In function ‘int main()’:
black_jack002-FLOW004.cpp:14:15: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
14 | last=n%10;
| ~^~~
black_jack002-FLOW004.cpp:18:23: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
18 | first=n;
| ^
^R
Successful
[simon@simon-laptop][18:53:50]
[~/devel/hackerrank/otherpeoples]>echo "1
3" | ./a.out
3
(The first digit of 3
is 3
; the last digit of 3
is 3
; so the sum of the first and last digit is 6
).
1 Like
i don’t get it . when i try 3 its giving me correct solution.
here have a look :