Jump to content

I'm solving a problem on codeforces and it's suppose to get the integer values on a straight line so I made up an equation and substitute in it but it say wrong answer so any tip ?

#include<bits/stdc++.h>using namespace std;int main(){    double x1,y1,x2,y2;    int num;    cin>>num;    int result[num];    for(int j=0; j<num; j++)    {        int counter=0;        cin>>x1>>y1>>x2>>y2;        double m=(y2-y1)/(x2-x1);        double c=(y1-(m*x1));        for(int i=min(x1,x2)+1; i<max(x1,x2); i++)        {            double y=((m*i)+c);            int z=y;            if(y==z)                counter++;        }        result[j]=counter;    }    for(int i=0; i<num; i++)    {        cout<<result[i]<<endl;    }    return 0;} 
Link to comment
https://linustechtips.com/topic/478288-c-problem-solving/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×