Hello coders, today we are going to solve Buggy Calculator Codechef Solution.

Problem
Trans bought a calculator at creatnx’s store. Unfortunately, it is fake. It has many bugs. One of them is adding two numbers without carrying. Example expression: 12 + 9 will have result 11 in his calculator. Given an expression in the form a + b, please output result from that calculator.
Input
The first line contains an integer T denote the number of test cases. Each test case contains two integers a, b in a single line.
Output
Each test case, print answer in a single line.
Constraints
- 1 ≤ T ≤ 100
- 1 ≤ a, b ≤ 109
Subtasks:
- Subtask #1 (30 points): 1 ≤ a, b ≤ 9
- Subtask #2 (70 points): original constrains
Sample Input 1
2 12 9 25 25
Sample Output 1
11 40
Buggy Calculator CodeChef Solution in JAVA
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int tcases = sc.nextInt(); while(tcases-->0) { int a = sc.nextInt(); int b = sc.nextInt(); int sum=0; int count=0; while(a>0 || b>0) { int dig = ((a%10)+(b%10))%10; sum = dig*(int)Math.pow(10,count)+sum; a=a/10; b=b/10; count++; } System.out.println(sum); } } }
Buggy Calculator CodeChef Solution in CPP
#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ int a,b,r1,r2,res,f=1,sum=0; cin>>a>>b; while(a>0 || b>0) { r1=a%10; r2=b%10; res=(r1+r2)%10; sum+=res*f; f*=10; a=a/10; b=b/10; } cout<<sum<<endl; } return 0; }
Buggy Calculator CodeChef Solution in Python
import math def xsum(a,b): multiplier=1 bit_sum=0 res=0 while(a or b): bit_sum=((a%10) +(b%10)) bit_sum=bit_sum%10 res=(bit_sum*multiplier)+res a=math.floor(a/10) b=math.floor(b/10) multiplier=multiplier*10 return res for i in range(int(input())): a,b=map(int,input().split()) print(xsum(a,b))
Disclaimer: The above Problem (Buggy Calculator) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.