-
Notifications
You must be signed in to change notification settings - Fork 101
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name of the parameter should be equation |
||
{ | ||
int t=0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} |
There was a problem hiding this comment.
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