2019程序设计基础第二次月考(BY) 解题报告

cww970329 edited 4 年,4 月前

下次增加题目难度分布的方差,加大力度

A

for 循环小练习,把

“男女序号每轮递加,达到最大值重新初始化”

#include<stdio.h>
int main()
{
    int a,b,round;
    scanf("%d %d %d",&a,&b,&round);
    int m=0,n=0,i;
    for(i=0;i<round;i++)
    {
        m=m+1;
        n=n+1;
        if(m>a) m=1;
        if(n>b) n=1;
        printf("%d %d\n",m,n);

    }
    return 0;
}

First Blood: 齐海昕, HarisonChih

B

好多人读入字符串,其实只要scanf("%d:%d:%d", &h, &m, &s);就可以了

语文题,多重if判断

#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    while(n--) {
        int hour, minute, sceond;
        scanf("%d:%d:%d", &hour, &minute, &second);
        int t0 = 8*60*60;
        int t = ((hour*60)+minute)*60+second;
        int d = t0 - t;
        if(d<10*60) {
            printf("You are late!\n");
        } else if(d<15*60){
            printf("Hurry up!\n");
        } else {
            printf("You are living a healthy life!\n");
        }
    }
    return 0;
}

读取时间,转化为秒( t 为出发时间),计算与上课时间的差(d),对于时间差进行判断。(注:全部以秒为单位)

但是由于题目描述,能买早饭就一定要买,所以只能是前者。(此处为坑)

然后就好了

—By Yoshino-s

Frist Blood: 崔晨洋, yoshino-s

C

不要被题目吓到,这是一道找规律题

#include<bits/stdc++.h>
using namespace std;
main(){
    string s;
    int flag = 1;
    while (cin >> s){
        for(int i = 0; i < s.size(); i++){
            if(s[i]=='.'||s[i]=='\''||s[i]=='?'||s[i]==','||(s[i]>='0'&& s[i]<='9')) {
                s[i] = '\0';
                break;
            }
        }
        if (s == "is" || s == "are" || s == "in" || s == "and"){
            cout<<"English"<<endl;
            return 0;
        }
        if (s.size() > 6) flag = 0;
    }
    if (flag) cout << "Chinese" << endl;
    else cout << "Japanese" << endl;
}

First Blood: 周佳馨, 5033一生推

D

题目要求对t组数据的每组n个数统计<=10的数的个数。

定义一个计数器ans。外循环对t循环,里循环对n循环。遍历完每组的n个数后输出ans即可。记得对计数器ans归零。

#include <stdio.h>

int main() {
    int t, i, j, ans = 0;
    scanf("%d", &t);
    for(i = 1; i <= t; i++){
        int n;
        scanf("%d", &n);
        int a;
        ans = 0;
        for (j = 0; j < n; j++){
            scanf("%d", &a);
            if (a <= 10) ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

First Blood: 周孜为, 滋味233

总结

参考题目练习:https://acm.ecnu.edu.cn/contest/124/

Comments

玖槭_977

B的题解
定义变量时间的时候second打错了呃
另外没搞懂这句:
如果时间差大于等于20分钟,迟到了(“You are late!”)
感觉应该是必不迟到,”You are living a healthy life!”

其他思路:
首先是小时,醒来时会有三种情况,即7点前,7点到8点,8点后。
先用if分为7点前、8点后,易得分别对应”You are living a healthy life!”和”You are late!”。

7点又分为三部分:45分之前,45分后50分之前,50分之后,分别对应”You are living a healthy life!”、“Hurry up!”和”You are late!”。

代码:(C++)

#include<iostream>

using namespace std;

int main(){

    int n;

    cin>>n;

    while(n--) {

        int hour, minute, second;

        scanf("%d:%d:%d", &hour, &minute, &second);

        if      (hour<7){

            cout<<"You are living a healthy life!"<<endl;

        }

        else if (hour>7){

            cout<<"You are late!"<<endl;

        }

        else            {

            if      (minute>=0&&minute<=45)
                cout<<"You are living a healthy life!"<<endl;
            else if (minute>45&&minute<50)
                cout<<"Hurry up!"<<endl;
            else if (minute==50&&second==0)
                cout<<"Hurry up!"<<endl;
            else
                cout<<"You are late!"<<endl;

        }
    }

    return 0;

}
cww970329

其实 这道题的本质就是看看能不能找得到别的语言里没有的单词,比如you在中文和英语都有,de在中文和罗马音里都有,所以就要靠肉眼找一下独特的单词(或者ctrl+F)。
而且需要注意,题目里说日语可能混英语,直接找英文单词可能会出错,所以最好先判断中文和日文,如果都不是就判断为英文。

#include <stdio.h>
#include <string.h>

int main()
{
    char word[40];
    while(~scanf("%s",&word))
    {
        if(strcmp(word,"guo")==0)
        {
            printf("Chinese");
            return 0;
        }
        if(strcmp(word,"chuan")==0)
        {
            printf("Chinese");
            return 0;
        }
        if(strcmp(word,"zhong")==0)
        {
            printf("Chinese");
            return 0;
        }
        if(strcmp(word,"yun")==0)
        {
            printf("Chinese");
            return 0;
        }



        if(strcmp(word,"kishi")==0)
        {
            printf("Japanese");
            return 0;
        }
        if(strcmp(word,"mashi")==0)
        {
            printf("Japanese");
            return 0;
        }
        if(strcmp(word,"sanka")==0)
        {
            printf("Japanese");
            return 0;
        }
        if(strcmp(word,"ga")==0)
        {
            printf("Japanese");
            return 0;
        }

    }
    printf("English");
    return 0;
}

中文很好过的,反正你自己也知道哪些只有拼音有,而且很常用(不知道的推荐回小学复读),
日文的话,。。。
大不了把if 复制个10次,随便粘贴几个罗马音,总能过的(๑•̀ㅂ•́)و✧(而且因为你已经把中文过掉了,所以可以不担心拼音有没有的问题)

——zcz

沖沖沖

C题用cpp是怎么输出的,为什么点回车没输出