#gesp3s24. 2024GESP三级字符串

2024GESP三级字符串

2024GESP三级字符串

2403真题

1.(2403-5)已知字符 '0' 的ASCII编码的十进制表示为48,则执行下面C++代码后,输出是()?

int main()
{
    string s="316";
    int n=s.length();
    int x=0;
    for(int i = 0; i < n; i++)
    	x += s[i];
    cout << x << endl;
    
    cout << endl;
    return 0;
}

{{ select(1) }}

  • 10
  • 58
  • 154
  • 316

2.(2403-8)在下列代码的横线处填写( ),可以使得输出是 GESP IS INTERESTING()?

int main()
{
    string str="gEsP is Interesting";
    int x = str.length();
    
    for(int i = 0; i < x; i++)
    	if ((str[i]>='a') && (str[i]<='z'))
    		________________________;
    cout << str << endl;
    
    cout << endl;
    return 0;
}

{{ select(2) }}

  • str[i]+='a'-'A'
  • str[i]+=20
  • str[i]+='A'-'a'
  • 无法实现

3.(2403-9)假设英文句子由若干词构成。下面C++代码统计输出的词数是()?

int main()
{
    string str="gEsP is Interesting !";
    int x = str.length();
    int nwords = 0;
    for(int i = 0; i < x; i++)
        if (str[i]==' '){
        	nwords++;
        	while(str[++i]==' ') ;
        }
    cout << nwords << endl;

    cout << endl;
    return 0;
}

{{ select(3) }}

  • 1
  • 2
  • 3
  • 4

4.(2403-12)定义字符数组 char str[20] = {'G', 'E', 'S', 'P'}; ,则 str 的字符串长度为()?{{ select(4) }}

  • 4
  • 5
  • 19
  • 20

2406真题

1.(2406-9)如果字符串定义为 char str[] = "GESP"; ,则字符数组 str 的长度为()?{{ select(5) }}

  • 0
  • 4
  • 5
  • 6

2.(2406-12)如已知字符 '0' 的ASCII编码的十进制表示为48,则执行下面C++代码后,输出是()?

#include <iostream>
using namespace std;

int main() {
    string s = "0629";
    
    int n = s.length();
    int x = 0;
    for(int i = 0; i < n; i++)
    	x += s[i];
    
    cout << x << endl;
    return 0;
}

{{ select(6) }}

  • 17
  • 158
  • 209
  • 316

3.(2406-14)下面可以正确输出 They're planning a party for their friend's birthday. 的C++语句是()?{{ select(7) }}

  • cout << 'They're planning a party for their friend'\s birthday." << endl;
  • cout << "They're planning a party for their friend's birthday.'<< endl;
  • cout << 'They're planning a party for their friend's birthday.'<< endl;
  • cout << "They're planning a party for their friend's birthday." << endl;

4.(2406-15)如果执行下面C++代码后,输出的结果是“gesp ccf org cn ”,则横线上应填入哪个代码()?

#include <iostream>
using namespace std;

int main() {
    string str = "gesp.ccf.org.cn";
    
    string delimiter = ".";
    string result="";
    string token;
    size_t found = str.find(delimiter);
    while (found != string::npos) {
        token = str.substr(0, found);
        result += token;
        result += " ";
        __________________________ // 在此处填入代码
        found = str.find(delimiter);
    }
    
    //最后一部分
    result += str;
    result += " ";
    cout << result << endl;
    return 0;
}

{{ select(8) }}

  • str = str.substr(found + delimiter.length(), str.length() - 1);
  • str = str.substr(found, str.length() );
  • str = str.substr(found, str.length() -1);
  • 以上都不对

2409真题

1.(2409-15)下列程序输出的是()?

string str = "Hello,陈A歹";
cout << str.find("A") << '\n';

{{ select(9) }}

  • 9
  • 8
  • 7
  • 6

2412真题

1.(2412-7)下列代码输出的是()?

string s="1234@@chenadai";
string str="12345";
s.replace(1,5,str);
cout<<s<<endl;

{{ select(10) }}

  • 12345
  • 2345@
  • 112345chenadai
  • 12345chenadai

2.(2412-9)下列程序输出的是( )?

string ch="hello";
if(ch[5]==NULL)
{
	cout<<"right"<<endl;
}
else if (ch[5]=='\0')
{
	cout<<"wrong"<<endl;
}
else
{
	cout<<"hello"<<endl;
}

{{ select(11) }}

  • right
  • wrong
  • hello
  • 不能正确执行

3.(2412-10)下列程序中,假设一个字符占用的内存空间是1,下列程序中,ch占用的内存空间 ()?

char ch[] = "hello world";
size_t ret=strlen(ch);
cout<<ret<<endl;

{{ select(12) }}

  • 11
  • 10
  • 13
  • 12

4.(2412-11)下列代码输出的是()?

int a=65;
cout<<tolower(a)<<endl;

{{ select(13) }}

  • 65
  • A
  • a
  • 97