#4248: 自訂結構出錯??


s89162504 (奕(25th))

學校 : 國立新竹高級中學
編號 : 8643
來源 : [111.243.105.123]
最後登入時間 :
2022-11-19 23:56:52
d093. 00477 - Points in Figures: Rectangles and Circles -- UVa477 | From: [61.230.185.102] | 發表日期 : 2010-09-17 00:02

小弟人生第一次用struct解題

結果......

#include<iostream>
#include<cmath>

using namespace std;

struct figure
{
       char  form;
       double a;
       double b;
       double c;
       double d;
};

struct dot
{
       double x;
       double y;
};
char  test;
      int t;
      struct  figure F[10];
      struct  dot    D[15];
      double  temp1,temp2;
      int i;
      bool s;

main()
{
     
     
      while(1)
      {
      t=0;
      while(cin.get(test))
      {
            if(test!='*')
                 {
                       if(test=='r'){
                                          F[t].form=test;
                                          cin>>F[t].a>>F[t].b>>F[t].c>>F[t].d;
                                          t++;  
                                     }
                                   
                       if(test=='c'){
                                          F[t].form=test;
                                          cin>>F[t].a>>F[t].b>>F[t].c;
                                          t++;
                                     }
                 }
            else {break;}         
      }
     
      i=0;
      while(cin>>temp1>>temp2)
      {
            if(temp1!=9999.9){
                                   D[i].x=temp1;
                                   D[i].y=temp2;
                                   i++;
                              }
            else {break;}
      }
     
      for(int j=0;j<i;j++)
      {
              s=false;
              for(int k=0;k<t,k<10;k++)
              {
                      if(F[k].form=='r')
                            if(D[j].x>F[k].a && D[j].x<F[k].c &&
                               D[j].y<F[k].b && D[j].y>F[k].d)
                                             {
                                              s=true;
                                              cout<<"Point "<<j+1<<" is contained in figure "<<k+1<<endl;
                                             }
                      if(F[k].form=='c')
                            if((F[k].a-D[j].x)*(F[k].a-D[j].x)+(F[k].b-D[j].y)*(F[k].b-D[j].y)<(F[k].c)*(F[k].c))
                                            {
                                             s=true;
                                             cout<<"Point "<<j+1<<" is contained in figure "<<k+1<<endl;                                                        
                                             }
              }
              if(!s)
                  cout<<"Point "<<j+1<<" is not contained in any figure"<<endl;
      }

      }
           return 0;
}
 

 

本題目共 2 個測試點,您沒有通過任何一個測試點。(score:0)
錯誤訊息如下:

*** 第 1 點 (50%):RE (SIGABRT)
執行時發生錯誤 (SIGABRT)(6)!!
系統呼叫 abort 函式!!
可能的原因為取用了超過string長度的位置、指標錯誤或 overflow。*** glibc detected *** malloc(): memory corruption (fast): 0x0804a008 ***
sh: line 1: 25784 已經終止            /tmp/code_566120.exe <d093.in >/tmp/code_566120.out

*** 第 2 點 (50%):RE (SIGABRT)
執行時發生錯誤 (SIGABRT)(6)!!
系統呼叫 abort 函式!!
可能的原因為取用了超過string長度的位置、指標錯誤或 overflow。*** glibc detected *** malloc(): memory corruption (fast): 0x0804a008 ***
sh: line 1: 25793 已經終止            /tmp/code_566120.exe <d093_1.in >/tmp/code_566120.out

 

請教各位大大

請問一下是哪裡出錯啊?

還有

這題把double換成float為什麼不行??

 
ZeroJudge Forum