上機考程式碼答案

每頁標題為超連結 可跳轉至zerojudge

-葉子齊-

#include <iostream>
using namespace std;
int main()
{
    string m;
    int n;
    cin>>m>>n;
    cout<<"I want "<<n<<" "<<m<<", thanks!";
    return 0;
}

出題者:林芊妘(教學長)

#include<iostream>
using namespace std;
int main()
{
	string s;
	while(getline(cin,s)) //用getline讓字串輸入不會被截斷
	{
		for(int i=0; i<s.length(); i++)
		{ //無限判斷字串中的字源是否有符合上述的五個字
		    if(s[i]=='K' && s[i+1]=='e' && s[i+2]=='n' && s[i+3]=='s' && s[i+4]=='h' && s[i+5]=='i')
			{
			    for(int j=i;j<=i+5;j++)  s[j]='0';
			}
			if(s[i]=='Y' && s[i+1]=='o' && s[i+2]=='n' && s[i+3]=='e' && s[i+4]=='z' && s[i+5]=='u')
			{
			    for(int j=i;j<=i+5;j++) s[j]='0';
			}
			if(s[i]=='c' && s[i+1]=='o' && s[i+2]=='n')
			{
			    for(int j=i;j<=i+2;j++) s[j]='0';
				if(s[i+3]=='c' && s[i+4]=='e' && s[i+5]=='r' && s[i+6]=='t')
				{
				    for(int j=i+3;j<=i+6;j++) s[j]='0';
				}
			}
			if(s[i]=='L' && s[i+1]=='e' && s[i+2]=='m' && s[i+3]=='o' && s[i+4]=='n')
			{
			    for(int j=i;j<=i+4;j++) s[j]='0';
			}
		}
		if(s=="0") break; //輸入0,則跳出迴圈結束
		cout<<s<<endl;
	}
}

出題者:林芊妘(教學長)

#include <iostream>
using namespace std;
int main()
{
    int Y=0,light=0,small=0,middle=0,large=0,sum=0,x=0;
    
    while(cin>>Y>>light>>small>>middle>>large){
        if(Y>=51 && Y<=69 && light<=7){
            sum=small+(middle*2)+(large*3);
            if(sum>=100)
                cout<<"已經100顆辣!!"<<endl;
            else{
                x=100-sum;
                cout<<"還有"<<x<<"顆,加油!!"<<endl;
            }
        }
        else{cout<<"這裡根本沒有史萊姆!!"<<endl;}
        x=0;
        sum=0;
    }
    return 0;
}

出題者:葉子齊(副社長)

#include <iostream>
using namespace std;
int main()
{
    int D=0,X=0,EXP=0,Today_EXP=0,Total_EXP=0;
    while(cin>>D>>X>>EXP){
        for(int multiple=1;multiple<=D;multiple++){  //multiple倍數
          Today_EXP=(X*EXP)*multiple;
          Total_EXP+=Today_EXP;
        }
        cout<<Total_EXP<<endl;
        Today_EXP=0;
        Total_EXP=0;
    }
    
    return 0;
}

出題者:葉子齊(副社長)

解法一:

#include <iostream>
using namespace std;
int main()
{
    int D=0,X=0,EXP=0;
    while(cin>>D>>X>>EXP){
        cout<<X*EXP*((D+1)*D/2)<<endl;
    }
    
    return 0;
}

出題者:葉子齊(副社長)

解法二:

#include <iostream>
using namespace std;

int calculate(int m, int prices, int count){
    if(count==m) return prices;
    else{
        count++;
        return count*calculate(m, prices, count);
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    int prices[101];
    for (int i = 1; i <= n; i++) {
        cin >> prices[i];
        int count = 1;
        int ans = calculate(m, prices[i], count);
        if(ans > 10000) cout << 10000 << ' ';
        else cout << ans << ' ';
    }
    cout << endl;
}

出題者:蔡其霏(教學)

上機考程式碼答案

By strange_swing

上機考程式碼答案

  • 226