3 solutions

  • -1
    @ 2025-7-16 16:27:51
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int x,y,z;
    	cin>>x>>y>>z;
    	if(y<0) 
    	{
    		x=-x;
    		y=-y;
    		z=-z;
    	}
    	if(x<y)
    	{
    		cout<<abs(x);
    	}
    	else
    	{
    		if(z>y)
    		{
    			cout<<-1;
    		}
    		else
    		{
    			cout<<abs(z)+abs(x-z); 
    		}
    	}
    	return 0;
    }
    
    
    
    • -2
      @ 2025-7-22 11:14:44
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int x,y,z,s=0;
      	cin>>x>>y>>z;
      	if(x>0)
      	{
      		if(y>x || y<0) s=x;
      		else
      		{
      			if(z<0) s=2*abs(z)+x;
      			else if(z<y) s=x;
      			else s=-1;
      		}
      	}
      	else
      	{
      		if(y>0 || y<x) s=abs(x);
      		else
      		{
      			if(z>0) s=2*z+abs(x);
      			else if(z>y) s=abs(x);
      			else s=-1;
      		}
      	}
      	cout<<s;
      	return 0;
      }
      
      • -2
        @ 2025-4-18 18:42:56
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int x,y,z;
        	cin>>x>>y>>z;
        	if(y<0) //强行让墙到大于0的位置
        	{
        		x=-x;
        		y=-y;
        		z=-z;
        	}
        	if(x<y) //可以直接走到
        	{
        		cout<<abs(x);
        	}
        	else
        	{
        		if(z>y) //锤子在墙的后边
        		{
        			cout<<-1;
        		}
        		else //先拿锤子,再到终点
        		{
        			cout<<abs(z)+abs(x-z); 
        		}
        	}
        	return 0;
        }
        
        
        • 1

        Information

        ID
        2365
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        3
        Tags
        (None)
        # Submissions
        148
        Accepted
        39
        Uploaded By