第三次模擬考 (使用2017-03-04 APCS模擬考試題)


給學生的題本:https://hackmd.io/OJN4j6WjQCSP3pjWZuq9jA?view

給學生的解答本:https://hackmd.io/eELt6_3XTEqeauyK9m4zbw?view


實作題
https://apcs.csie.ntnu.edu.tw/files/1060304APCSImplementation.pdf

觀念題
https://apcs.csie.ntnu.edu.tw/files/1060304APCSconcept.pdf


第 1 題 秘密差

字串版

#include <bits/stdc++.h>
using namespace std;
int main(){
    string str;
    int evenSum,oddSum;
    while(cin >> str){
        evenSum=0;
        oddSum=0;
        for(int i=0;i<str.length();i++){
            if (i%2){
                evenSum += str[i]-'0';
            }else{
                oddSum += str[i]-'0';
            }
        }
        cout << abs(evenSum-oddSum) << endl;
    }
}

數字版

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

int main(){
    int n,t=1;
    int oddSum = 0;
    int evenSum = 0;
    while(cin>>n){
        while(n>0){
            if(t>0)
            oddSum+=n%10;
            else
            evenSum+=n%10;
            t=-t;
            n=n/10;
        }
        cout<<abs(oddSum-evenSum)<<endl;
    }
}

第 2 題 小群體

#include<iostream>
using namespace std;

int main(){
    int n,cnt; //cnt就是count,代表群組的數目
    int partnerOf[50000]; //成員
    bool inGroup[50000]; //有沒有被拜訪過
    int tmp;
    while(cin>>n){
        for(int i=0;i<n;i++){
            cin>>partnerOf[i]; // 輸入每個人的好友是誰
            inGroup[i]=false;
        }
        //===================
        cnt=0; //群組的數目
        for(int i=0;i<n;i++){

            //如果i已經被分到小群體了,就Pass
            if(inGroup[i])continue; 

            inGroup[i]=true; //把i放進小群體裡
            tmp = partnerOf[i];

            while(i!=partnerOf[tmp]){
                inGroup[tmp]=true;
                tmp=partnerOf[tmp];
            }
            inGroup[tmp]=true;
            cnt++;
        }
        cout<<cnt<<endl;
    }
}

第 3 題 數字龍捲風

#include<iostream>
using namespace std;

int main(){
    //0左 1上 2右 3下
    int a[50][50];
    int n, dir;

    cin >> n >> dir;
    for (int i= 0; i < n;i++)
    for (int j= 0; j < n;j++)
    cin >> a[i][j];

    int c= n / 2;
    int step= 1;
    int cnt= 0;
    int x= c, y = c;

    cout << a[y][x];

    while (step < n) {
        for (int i= 0; i < step;i++){
            switch (dir) {
                case 0: cout << a[y][--x]; break;
                case 1: cout << a[--y][x]; break;
                case 2: cout << a[y][++x]; break;
                case 3: cout << a[++y][x]; break;
            }
        }
        dir += 1;
        cnt++;
        if (dir > 3) dir = 0;
        if (cnt == 2) {
            cnt = 0;
            step++;
        }
    }

    step--;
    for (int g= 0; g < 1;g++){
        for (int i= 0; i < step;i++){
            switch (dir) {
                case 0: cout << a[y][--x]; break;
                case 1: cout << a[--y][x]; break;
                case 2: cout << a[y][++x]; break;
                case 3: cout << a[++y][x]; break;
            }
        }
        dir += 1;
        if (dir > 3) dir = 0;

    }

}

第 4 題 基地台

https://sites.google.com/site/zsgititit/zi-xun-neng-li-jian-ding/apcs/10603di4ti-ji-de-tai

// 待補上

results matching ""

    No results matching ""