历年CSP-J初赛真题解析 | 2015年CSP-J初赛阅读程序(23-26)

学习C++从娃娃抓起!记录下CSP-J备考学习过程中的题目,记录每一个瞬间。

附上汇总贴:历年CSP-J初赛真题解析 | 汇总_热爱编程的通信人的博客-CSDN博客


#include<iostream>
using namespace std;
int main() {
    int a, b, c;
    a = 1; b = 2; c = 3;
    if (a>b) {
        if (a>c) 
            cout << a << ' ';
        else
            cout << b << ' ';
    }
    cout << c << endl;
    return 0;
}

第23题

输出:( )

【答案】:3

【解析】

模拟,因为a>b,所以第6行至第第10行都不执行。最后只输出c

#include <iostream>
using namespace std;
struct point {
    int x;
    int y;
};
int main() {
    struct EX {
        int a;
        int b;
        point c;
    }e;
    e.a = 1;
    e.b = 2;
    e.c.x = e.a + e.b;
    e.c.y = e.a * e.b;
    cout << e.c.x << ' ' << e.c.y << endl;
    return 0;
}

第24题

输出:( )

【答案】:3 2

【解析】

在这里插入图片描述

#include <iostream>
#include <string>
using namespace std;
int main() {
    string str;
    int i;
    int count;
    count = 0;
    getline(cin, str);
    for (i=0; i<str.length(); i++) {
        if (str[i]>='a' && str[i]<='z')
            count++;
    }
    cout << "It has " << count << " lowercases" << endl;
    return 0;
}

第25题

输入:NOI2016 will be held in Mian Yang.

输出:( )

【答案】:It has 18 lowercases

【解析】

题目是输出字符串中所有小写字母的数量,共18个。

#include <iostream>
using namespace std;
void fun(char *a, char *b) {
    a = b;
    (*a) ++;
}
int main() {
    char c1, c2, *p1, *p2;
    c1='A';
    c2='a';
    p1 = &c1;
    p2 = &c2;
    fun(p1, p2);
    cout << c1 << c2 << endl;
    return 0;
}

第26题

输出:( )

【答案】:Ab

第4行,a = b 就是 a = &c2,那么第5行修改*a的值,就是在修改c2的值,

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值