首页 › 题库 › 信息学奥赛 › 2 C++语言基础

信息学奥赛-入门级 题库

共 766 道题 ,第 32 / 39 页 · 按题型筛选,点「查看答案」核对解析
章节 2 C++语言基础 清除
621 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main() {
	int a, b, c, d, ans;
	cin >> a >> b >> c;
	d = a - b;
	a = d + c;
	ans = a * b;
	cout << "Ans = " << ans << endl;
	return 0;
}

输入: 2 3 4

输出:           

答案与解析
参考答案

Ans = 9

题目详情
622 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int fun(int n) {
	if (n == 1)
		return 1;
	if (n == 2)
		return 2;
	return fun(n - 2) - fun(n - 1);
}

int main() {
	int n;
	cin >> n;
	cout << fun(n) << endl;
	return 0;
}

输入: 7

输出:           

答案与解析
参考答案

-11

题目详情
623 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string st;
	int i, len;
	getline(cin, st);
	len = st.size();
	for (i = 0; i < len; i++){
		if (st[i] >= 'a' && st[i] <= 'z')
			st[i] = st[i] - 'a' + 'A';
	}
	cout << st << endl;
	return 0;
}

输入: Hello, my name is Lostmonkey.

输出:                                                     

答案与解析
参考答案

HELLO, MY NAME IS LOSTMONKEY.

题目详情
624 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

const int SIZE = 100;

int main()
{
	int p[SIZE];
	int n, tot, i, cn;
	tot = 0;
	cin >> n;
	for (i = 1; i <= n; i++)
		p[i] = 1;
	for (i = 2; i <= n; i++){
		if (p[i] == 1)
			tot++;
		cn = i * 2;
		while (cn <= n) {
			p[cn] = 0;
			cn += i;
		}
	}
	cout << tot << endl;
	return 0;
}

输入: 30

输出:              

答案与解析
参考答案

10

题目详情
625 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

7 个同学围坐一圈,要选2个不相邻的作为代表,有           种不同的选法。

答案与解析
参考答案

14

题目详情
626 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

某系统自称使用了一种防窃听的方式验证用户密码。密码是n个数 s1, s2, … , sn ,均为0或1。该系统每次随机生成n个数a1, a2, … , an,均为0或1,请用户回答(s1a1+s2a2+… +snan)除以2的余数。如果多次的回答总是正确,即认为掌握密码。该系统认为, 即使 问答的过程被泄露, 也无助于破解密码—— 因为用户并没有直接发送密码。

然而, 事与愿违。例如,当n= 4 时, 有人窃听了以下 5 次问答:

就破解出了密码 s1=               ,s2=               ,s3=                ,s4=                。

答案与解析
参考答案

s1 = 0,s2 = 1,s3 = 1,s4 = 1

题目详情
627 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	int a, b;
	cin>>a>>b;
	cout<<a<<"+"<<b<<"="<<a+b<<endl;
}


输入: 3 5

输出:                  

答案与解析
参考答案

3+5=8

题目详情
628 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	int a, b, u, i, num;

	cin>>a>>b>>u;
	num = 0;
	for (i = a; i <= b; i++)
		if ((i % u) == 0)
			num++;
	cout<<num<<endl;
	return 0;
}


输入: 1 100 15

输出:                   

答案与解析
参考答案

6

题目详情
629 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	const int SIZE = 100;

	int n, f, i, left, right, middle, a[SIZE];

	cin>>n>>f;
	for (i = 1; i <= n; i++)

		cin>>a[i];
	left = 1;
	right = n;
	do {
		middle = (left + right) / 2;
		if (f <= a[middle])
			right = middle;
		else
			left = middle + 1;
	} while (left < right);
	cout<<left<<endl;
	return 0;
}

输入:

12 17
2 4 6 9 11 15 17 18 19 20 21 25

输出:       

                                     

答案与解析
参考答案

7

题目详情
630 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	const int SIZE = 100;
	int height[SIZE], num[SIZE], n, ans;
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>height[i];
		num[i] = 1;
		for (int j = 0; j < i; j++) {
			if ((height[j] < height[i]) && (num[j] >= num[i]))
				num[i] = num[j]+1;
		}
	}
	ans = 0;
	for (int i = 0; i < n; i++) {

		if (num[i] > ans) ans = num[i];
	}
	cout<<ans<<endl;
}

输入:

6

2 5 3 11 12 4

输出:   

                            

答案与解析
参考答案

4

题目详情
631 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

如果平面上任取n个整点(横纵坐标都是整数) ,其中一定存在两个点,它们连线的中点也是整点,那么n至少是            。

答案与解析
参考答案

5

题目详情
632 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

在NOI期间,主办单位为了欢迎来自全国各地的选手,举行了盛大的晚宴。在第十八桌,有5名大陆选手和5名港澳选手共同进膳。为了增进交流,他们决定相隔就坐,即每个大陆选手左右相邻的都是港澳选手、每个港澳选手左右相邻的都是大陆选手。那么,这一桌共有            种不同的就坐方案。注意:如果在两个方案中,每个选手左边相邻的选手均相同,则视为同一个方案。

答案与解析
参考答案

2880

题目详情
633 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int a, b, c, d, e, ans;

int main()
{
	cin>>a>>b>>c;
	d = a+b;
	e = b+c;
	ans = d+e;
	cout<<ans<<endl;
}


输入: 1 2 5

输出:           

答案与解析
参考答案

10

题目详情
634 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include<iostream>
using namespace std;

int n, i, ans;

int main()
{
	cin>>n;
	ans = 0;
	for (i = 1; i <= n; i++)
		if (n % i == 0)
			ans++;
	cout<<ans<<endl;
}


输入: 18

输出:            

答案与解析
参考答案

6

题目详情
635 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>

using namespace std;
int n, i,j, a[100][100];

int solve(int x, inty)
{
	int u, v;

	if (x == n)
		return a[x][y];
	u = solve(x + 1, y);
	v = solve(x + 1, y + 1);
	if (u > v)
		return a[x][y] + u;
	else
		return a[x][y] + v;
}

int main()
{
	cin>>n;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= i; j++)
			cin>>a[i][j];
	cout<<solve(1, 1)<<endl;
	return 0;
}


输入 :

5

2

-1 4

2 -1 -2

-1 6 4 0

3 2 -1 5 8

输出:                     

答案与解析
参考答案

14

题目详情
636 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>

#include <string>
using namespace std;

int n, ans, i, j;
string s;

charget(inti)
{
	if (i < n)
		return s[i];
	else
		return s[i-n];
}
int main()
{
	cin>>s;
	n = s.size();
	ans = 0;
	for (i = 1; i <= n-1; i++)
	{
		for (j = 0; j <= n-1; j++) if (get(i+j) < get(ans+j))
		{
			ans = i;
			break;
		}
		else if (get(i+j) > get(ans+j))
			break;
	}
	for (j = 0; j <= n-1; j++)
		cout<<get(ans+j);
	cout<<endl;
}


输入: CBBADADA

输出:                   

答案与解析
参考答案

ACBBADAD

题目详情
637 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型

定义字符串的基本操作为:删除一个字符\插入一个字符和将一个字符修改成另外一个字符这三种操作。将字符串A变成字符串B的最少操作步数,称为字符串A到字符串B的编辑距离。字符串“ ABCDEFG  ”到字符串“   BADECG ”的编辑距离为            。

答案与解析
参考答案

3

题目详情
638 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型

#include<iostream>
using namespace std;
int main()
{
inti,n,m,ans;
cin>>n>>m;
i=n;
ans=0;
while(i<=m){
ans+=i;
i++;
}
cout<<ans<<endl;
return 0;
}

输入:   10 20

输出:                


答案与解析
参考答案

165

题目详情
639 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型

#include<iostream>
#include<string>
using namespace std;
int main()
{
string map= "2223334445556667778889999";
string tel;
inti;
cin>>tel;
for(i=0;i<tel.length();i++)
if((tel[i]>='0') && (tel[i]<='9') )
cout<<tel[i];
elseif( (tel[i]>='A') && (tel[i]<='Z'))
cout<<map[tel[i]-'A'];
cout<<endl;
return 0;
}

输入:   CCF-NOIP-2011

输出:                     


答案与解析
参考答案

22366472011

题目详情
640 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型

#include<iostream>
#include<cstring>
using namespace std;
const int SIZE = 100;
int main()
{
int n,i,sum,x,a[SIZE];
cin>>n;
memset(a,0,sizeof(a));
for(i=1;i<=n;i++){
cin>>x;
a[x]++;
}
i=0;
sum=0;
while(sum<(n/2+1)){
i++;
sum+=a[i];
}
cout<<i<<endl;
return 0;
}

输入:

11

4 5 6 6 4 3 3 2 3 2 1

输出:                  

答案与解析
参考答案

3

题目详情