4 条题解

  • 1
    @ 2025-10-2 11:27:18

    记得x和y的坐标都是实数类型而不是整数。

    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h> 
    
    
    int main(){
    	double x1,x2,y1,y2;
    	double juli;
    	while(scanf("%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2)!=EOF){
    		juli=sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
    		printf("%.2f\n",juli);
    	}
    	return 0;
    }
    
    • 0
      @ 2025-10-18 13:27:41
      #include<stdio.h>
      #include<math.h>
      #include<string.h>
      
      int main(){
      	double tot[100][4];
      	
      	int i=0;
      	while(scanf("%lf,%lf,%lf,%lf",&tot[i][0],&tot[i][1],&tot[i][2],&tot[i][3])!=EOF){
      		double t=sqrt((tot[i][0]-tot[i][2])*(tot[i][0]-tot[i][2])+(tot[i][1]-tot[i][3])*(tot[i][1]-tot[i][3]));
      		printf("%.2lf\n",t);
      		i++;
      	}				
         
         
         
      	return 0;
      }
      
      
      
      • 0
        @ 2025-10-1 10:28:47
        #include <iostream>
        #include <cstring>
        #include <cmath>
        #include <vector>
        #include <cstdio>
        using namespace std;
        int main()
        {
            string str;
            while(cin >> str)
            {
                vector<int> coord;
                int num = 0;
                for (size_t i = 0; i < str.size(); i++)
                {
                    if (str[i] == ',')
                    {
                        coord.push_back(num);
                        num = 0;
                        continue;
                    }
                    num = num * 10 + str[i] - 48;
                }
                coord.push_back(num);
        
                int x = abs(coord[2] - coord[0]),
                    y = abs(coord[3] - coord[1]);
                
                double ans = sqrt(x * x + y * y);
        
                printf("%.2f\n", ans);
            }
            return 0;
        }
        
        • 0
          @ 2024-11-4 23:08:28

          #include<bits/stdc++.h> using namespace std;

          //double x1,y1,x2,y2; 要是在这里声明变量 OJ会报错 但是自己测试答案是正确的 也不知道为什么

          double ans;

          void juli(double x_1,double y_1,double x_2,double y_2) { ans=sqrt((x_1-x_2)(x_1-x_2) + (y_1-y_2)(y_1-y_2)); printf("%.2f\n",ans); }

          int main() { double x1,y1,x2,y2;

          while(scanf("%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2)!=EOF)
          {
          	juli(x1,y1,x2,y2);
          }
          return 0;
          

          }

          • 1

          信息

          ID
          233
          时间
          1000ms
          内存
          256MiB
          难度
          7
          标签
          递交数
          609
          已通过
          134
          上传者