Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution of first problem #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions FixMultiplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
public class FixMultiplication
{

public static int isMissing(int t,int T)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method name should always follow Pascal Casing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method should be private, as the scope is within the class and outside.

{
int count=0;
int missing_digit = -1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to write code with proper formatting. This will make it more readable.

int[] ht = new int[10];
while(t!=0)
{
ht[t%10]++;
t/=10;
}
while(T!=0)
{
ht[T%10]--;
T/=10;
}
for(int i=0;i<=9;i++)
{
if(ht[i]==1)
{
count++;
missing_digit = i;
}
}
if(count!=1)
missing_digit = -1;
return missing_digit;
}
int FindDigit(string inp)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be public, as it is being accessed from Program.cs
Also, invoke this method from the Main method in Program.cs file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of the parameter should be equation

{
int t=0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the proper name of variables, instead of alphabets

string[] inp1 = inp.Split('=');
string[] inp2 = inp1[0].Split('*');
int A = Convert.ToInt32(inp2[0]);
int B = Convert.ToInt32(inp2[1]);
int C = Convert.ToInt32(inp1[1]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will break, as all inputs are not valid integers.


if(A*B<C)
{
int a = C/B;
int b = C/A;
if((t=isMissing(a,A))!=-1)
{
return t;
}
if((t=isMissing(b,B))!=-1)
{
return t;
}
return -1;
}
if(A*B>C)
{
return isMissing(A*B,C);
}
return -1;
}
public static void Main(String[] args)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This main method is part of Program.cs. Remove from here

{
string inp = Console.ReadLine();
FixMultiplication obj = new FixMultiplication();
Console.WriteLine(" "+obj.FindDigit(inp));
}
}