# C_APCS 能力檢定初階研習營 ###### tags: `中華電信` `program` :::info **時間:2021.01.25~26** * 09:10~12:00 * 13:30~16:20 **地點:中華電信學院** * 新北市板橋區民族路168號 * 綜合大樓G211教室 ::: ## <font color="#00f"> 講義 </font> [講義連結](https://drive.google.com/drive/folders/14O4Uah3tUlOizNjD2oEjCkN_Wld6VnqI?usp=sharing) * [Zerojudge](https://zerojudge.tw/) 課程代號: **m0fJK4** ## <font color="#00f"> 課程安排 </font> |日期|時間|課程主題|內容綱要|時數| |--|--|--|--|--| |2021.01.25(一)|09:10~10:30|APCS|APCS簡介、程式概念|1.5| |2021.01.25(一)|10:40~12:00|C,C++|input/out(輸出入)|1.5| |2021.01.25(一)|13:30~14:50|C,C++|資料與運算|1.5| |2021.01.25(一)|15:00~16:20|C,C++|程式流程規劃|1.5| |2021.01.26(二)|09:10~10:30|C,C++|基本資料結構|1.5| |2021.01.26(二)|10:40~12:00|C,C++|函數及遞迴|1.5| |2021.01.26(二)|13:30~14:50|APCS | 簡易模擬練習 | 1.5 | |2021.01.26(二)|15:00~16:20|APCS | 檢討及自我練習安排 | 1.5 | ## <font color="#00f"> APCS簡介 </font> * [教育部介紹網頁](https://apcs.csie.ntnu.edu.tw/index.php/apcs-introduction/) ## <font color="#00f"> 程式概念 </font> ```graphviz digraph hierarchy { nodesep=1.0 // increases the separation between nodes node [color=Black,fontname=Consolas,shape=box] //All nodes will this shape and colour edge [color=Blue, style=filled] //All the lines look like this 程式語言 -> {低階語言 高階語言} 低階語言 -> {組合語言} 高階語言 -> {編譯語言 直譯語言} {rank=same;組合語言 編譯語言 直譯語言} // Put them on the same level } ``` * C/C++屬於編譯語言,程式寫完後,編譯執行 * Java屬於編譯與直譯混合,程式寫完後,編譯成中介檔案再直譯執行。 * Python屬於直譯語言,程式可逐行執行。 ## <font color="#00f"> 練習一 </font> ### input/out(輸出入)、資料與運算 #### [a001. 哈囉](https://zerojudge.tw/ShowProblem?problemid=a001) ```c= #include <stdio.h> int main() { char str[1000]; scanf("%s",str); printf("hello, %s\n",str); return 0; } ``` #### [a002. 簡易加法](https://zerojudge.tw/ShowProblem?problemid=a002) ```c= #include <stdio.h> int main() { int a,b; scanf("%d%d",&a,&b); printf("%d\n",a+b); return 0; } ``` #### [a003. 兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003) ```c= #include<stdio.h> int main() { int m,d,s; scanf("%d %d",&m,&d); s=(m*2+d)%3; if(0==s) printf("普通\n"); else if(1==s) printf("吉\n"); else if(2==s) printf("大吉\n"); return 0; } ``` #### [a005. Eva 的回家作業](https://zerojudge.tw/ShowProblem?problemid=a005) ```c= #include <stdio.h> #include <stdlib.h> int main() { int n,a,b,c,d,e,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d%d%d",&a,&b,&c,&d); if(b-a==c-b && d-c==c-b) e=d+(b-a); else e=d*(b/a); printf("%d %d %d %d %d\n",a,b,c,d,e); } return 0; } ``` #### [a058. MOD3](https://zerojudge.tw/ShowProblem?problemid=a058) ```c= #include <stdio.h> int main() { int n,i,t,c0=0,c1=0,c2=0; scanf("%d",&n); for(i=0; i<n; i++) { scanf("%d",&t); if(t%3==0) c0++; else if(t%3==1) c1++; else c2++; } printf("%d %d %d\n",c0,c1,c2); return 0; } ``` ## <font color="#00f"> 練習二 </font> ### 迴圈及判斷式 #### [a244. 新手訓練 ~ for + if -- 新手訓練系列 ~ 1](https://zerojudge.tw/ShowProblem?problemid=a244) ```c= #include <stdio.h> int main() { long long n,a,b,c; scanf("%lld",&n); while(n--) { scanf("%lld %lld %lld",&a,&b,&c); if(a==1) printf("%lld\n",b+c); else if(a==2) printf("%lld\n",b-c); else if(a==3) printf("%lld\n",b*c); else if(a==4) printf("%lld\n",b/c); } return 0; } ``` #### [a053. Sagit's 計分程式](https://zerojudge.tw/ShowProblem?problemid=a053) ```c= #include <stdio.h> int main() { int n,score; //讀入題數 scanf("%d",&n); //判斷成績的區間 if(n<=10) score=n*6; // 10題以下: score=n*6 else if(n<=20) score=60+(n-10)*2; // 11~20題: score=60+(n-10)*2 else if(n<=40) score=80+(n-20);// 21~40題: score=80+(n-20) else score=100;// 40題以上: 100 //輸出成績 printf("%d\n",score); return 0; } ``` ```c= #include <stdio.h> int main() { int n,score; //讀入成績 while(scanf("%d",&n)!=EOF) { //判斷成績的區間 if(n<=10) score=n*6; // 10題以下: score=n*6 else if(n<=20) score=60+(n-10)*2; // 11~20題: score=60+(n-10)*2 else if(n<=40) score=80+(n-20);// 21~40題: score=80+(n-20) else score=100;// 40題以上: 100 printf("%d\n",score); } return 0; } ``` #### [a024. 最大公因數(GCD)](https://zerojudge.tw/ShowProblem?problemid=a024) ```c= ``` #### [a059. 完全平方和](https://zerojudge.tw/ShowProblem?problemid=a059) ```c= ``` #### [a020. 身分證檢驗](https://zerojudge.tw/ShowProblem?problemid=a020) ```c= #include <stdio.h> int main() { char id[11]; int an[26] ={10,11,12,13,14,15,16,17,34,18,19,20,21, 22,35,23,24,25,26,27,28,29,32,30,31,33 }; int n1,sum,i; // 輸入 scanf("%s",id); //id[0]:英文字母、其他id[i]是數字 // 處理 // 建表(查表) n1 = an[id[0]-'A']; //轉換 // 計算 sum = (n1%10)*9+n1/10; for(i=1; i<=8; i++) sum+= (id[i]-'0')*(9-i); sum+= (id[9]-'0'); // 比對輸出 if(sum%10==0) printf("real\n"); else printf("fake\n"); return 0; } ``` ## <font color="#00f"> 練習三 </font> ### 基本資料結構 ### 函數及遞迴 ### 簡易模擬練習