首页 › 题库 › 信息学奥赛 › 2.1 数据类型

信息学奥赛-入门级 题库

共 127 道题 ,第 4 / 7 页 · 按题型筛选,点「查看答案」核对解析
章节 2.1 数据类型 清除
61 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main() {
	string ch;
	int a[200];
	int b[200];
	int n, i, t, res;
	cin >> ch;
	n = ch.length();
	for (i = 0; i < 200; i++)
		b[i] = 0;
	for (i = 1; i <= n; i++) {
		a[i] = ch[i - 1] - '0';
		b[i] = b[i - 1] + a[i];
	}
	res = b[n];
	t = 0;
	for (i = n; i > 0; i--) {
		if (a[i] == 0)
			t++;
		if (b[i - 1] + t < res)
			res = b[i - 1] + t;
	}
	cout << res << endl;
	return 0;
}


输入: 1001101011001101101011110001

输出:             

答案与解析
参考答案

11

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

int main() {
	int n, m;
	cin >> n >> m;
	int x = 1;
	int y = 1;
	int dx = 1;
	int dy = 1;
	int cnt = 0;
	while (cnt != 2) {
		cnt = 0;
		x = x + dx;
		y = y + dy;
		if (x == 1 || x == n) {
			++cnt;
			dx = -dx;
		}
		if (y == 1 || y == m) {
			++cnt;
			dy = -dy;
		}
	}
	cout << x << " " << y << endl;
	return 0;
}


输入 1:4 3

输出 1:                 (3 分)

输入 2:2017 1014

输出 2:                 (5 分)

答案与解析
参考答案

输出 1:1 3

输出 2:2017 1

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

int main() {
	int max, min, sum, count = 0;
	int tmp;
	cin >> tmp;
	if (tmp == 0)
		return 0;
	max = min = sum = tmp;
	count++;
	while (tmp != 0) {
		cin >> tmp;
		if (tmp != 0) {
			sum += tmp;
			count++;
			if (tmp > max)
				max = tmp;
			if (tmp < min)
				min = tmp;
		}
	}
	cout << max << "," << min << "," << sum / count << endl;
	return 0;
}

输入: 1 2 3 4 5 6 0 7

输出:                   

答案与解析
参考答案

6,1,3

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

int main() {
	int i = 100, x = 0, y = 0;
	while (i > 0) {
		i--;
		x = i % 8;
		if (x == 1)
			y++;
	}
	cout << y << endl;
	return 0;
}

输出:           

答案与解析
参考答案

13

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

int main() {
	int a[6] = {1, 2, 3, 4, 5, 6};
	int pi = 0;
	int pj = 5;
	int t , i;
	while (pi < pj) {
		t = a[pi];
		a[pi] = a[pj];
		a[pj] = t;
		pi++;
		pj--;
	}
	for (i = 0; i < 6; i++)
		cout << a[i] << ",";
	cout << endl;
	return 0;
}

输出:                      

答案与解析
参考答案

6,5,4,3,2,1,

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

int main() {
	int i, length1, length2;
	string s1, s2;
	s1 = "I have a dream.";
	s2 = "I Have A Dream.";
	length1 = s1.size();
	length2 = s2.size();
	for (i = 0; i < length1; i++)
		if (s1[i] >= 'a' && s1[i] <= 'z')
			s1[i] -= 'a' - 'A';
	for (i = 0; i < length2; i++)
		if (s2[i] >= 'a' && s2[i] <= 'z')
			s2[i] -= 'a' - 'A';
	if (s1 == s2)
		cout << "=" << endl;
	else if (s1 > s2)
		cout << ">" << endl;
	else
		cout << "<" << endl;
	return 0;
}

输出:            

答案与解析
参考答案

=

题目详情
67 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#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;
}

输出:                     

答案与解析
参考答案

3

题目详情
68 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#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;

输入: NOI2016 will be held in Mian Yang.

输出:                                                 

答案与解析
参考答案

It has 18 lowercases

题目详情
69 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
70 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
71 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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.

题目详情
72 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
73 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
74 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
75 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
76 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
77 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
78 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
79 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情
80 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 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

题目详情