#172: 囧!為什麼是CE?


dowdow (QC.L of WLCSC)

學校 : 國立武陵高級中學
編號 : 1013
來源 : [140.112.25.49]
最後登入時間 :
2012-03-23 10:04:16
c050. 00453 - Goldbach's Conjecture -- UVa543 | From: [61.231.167.1] | 發表日期 : 2008-02-18 00:10

程式碼如下,為何ce?在我家執行一切正常。

#include <stdio.h>

#define N 1000000
int main()

      bool primer[N]={0};
      int p[78498];
      long i,j,cc=0;
      for(i=2;i<N;i++){

      if(primer[i] == 1){
      continue;}else{p[cc]=i;cc++;}
      for(j=i+i;j<N;j=j+i)
      primer[j]=1;
      }
     
      long n,ch;
          
      while(scanf("%d",&n)!=EOF){
      if(n == 0)
      break;
      ch=0;
      for(i=0;i<78498;i++){
        if(primer[n-p[i]]==0){printf("%d = %d + %d\n",n,p[i],n-p[i]);ch++;break;}
      }         
      if(ch==0){printf("Goldbach's conjecture is wrong.\n");}
      }
     
      return 0;
}

 
#173: Re:囧!為什麼是CE?


POOHccc ()

學校 : 國立臺中技術學院
編號 : 1139
來源 : [220.135.97.253]
最後登入時間 :
2012-02-04 21:23:42
c050. 00453 - Goldbach's Conjecture -- UVa543 | From: [220.134.60.246] | 發表日期 : 2008-02-18 12:52

看了編譯回傳的結果

編譯錯誤,請檢查語法是否符合系統(ANSI/ISO C/C++ by GNU)的要求。
錯誤訊息:
/tmp/code_11706.c: In function `main':
/tmp/code_11706.c:6: error: `bool' undeclared (first use in this function)
/tmp/code_11706.c:6: error: (Each undeclared identifier is reported only once
/tmp/code_11706.c:6: error: for each function it appears in.)
/tmp/code_11706.c:6: error: parse error before "primer"
/tmp/code_11706.c: At top level:
/tmp/code_11706.c:9: error: parse error before "for"
/tmp/code_11706.c:13: error: conflicting types for 'j'
/tmp/code_11706.c:8: error: previous declaration of 'j' was here
/tmp/code_11706.c:13: error: initializer element is not constant
/tmp/code_11706.c:13: error: parse error before ')' token
/tmp/code_11706.c:19: error: parse error before "while"
/tmp/code_11706.c:22: error: conflicting types for 'ch'
/tmp/code_11706.c:17: error: previous declaration of 'ch' was here
/tmp/code_11706.c:22: warning: data definition has no type or storage class
/tmp/code_11706.c:23: error: parse error before "for"
 

 

解題語言改用C++就會過了 

 
#174: Re:囧!為什麼是CE?


debugger (殺蟲劑)

學校 : 不指定學校
編號 : 1
來源 : [163.32.93.124]
最後登入時間 :
2023-10-31 17:39:44
c050. 00453 - Goldbach's Conjecture -- UVa543 | From: [163.32.93.88] | 發表日期 : 2008-02-18 17:16

看了編譯回傳的結果

編譯錯誤,請檢查語法是否符合系統(ANSI/ISO C/C++ by GNU)的要求。
錯誤訊息:
/tmp/code_11706.c: In function `main':
/tmp/code_11706.c:6: error: `bool' undeclared (first use in this function)
/tmp/code_11706.c:6: error: (Each undeclared identifier is reported only once
/tmp/code_11706.c:6: error: for each function it appears in.)
/tmp/code_11706.c:6: error: parse error before "primer"
/tmp/code_11706.c: At top level:
/tmp/code_11706.c:9: error: parse error before "for"
/tmp/code_11706.c:13: error: conflicting types for 'j'
/tmp/code_11706.c:8: error: previous declaration of 'j' was here
/tmp/code_11706.c:13: error: initializer element is not constant
/tmp/code_11706.c:13: error: parse error before ')' token
/tmp/code_11706.c:19: error: parse error before "while"
/tmp/code_11706.c:22: error: conflicting types for 'ch'
/tmp/code_11706.c:17: error: previous declaration of 'ch' was here
/tmp/code_11706.c:22: warning: data definition has no type or storage class
/tmp/code_11706.c:23: error: parse error before "for"
 

 

解題語言改用C++就會過了 


上面的編譯錯誤說明了 C 語言沒有定義 bool

很怪吧,純 C  裡就用整數 0 or 1來 處理 boolean 吧

用純 C 寫 連 // 這種註解符號都不行哦... 

 

 
ZeroJudge Forum