栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

慧通编程第九关

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

慧通编程第九关

991 有序插入
#include 
using namespace std;

const int N = 109;
int n, a[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	cin >> a[++n];
	
	int k = n;
	while (a[k] > a[k-1] && k >= 2) {
		swap(a[k], a[k-1]);
		k --;
	}
	
	for (int i = 1; i <= n; i ++) cout << a[i] << ' ';

	return 0;
}
992 插队
#include 
using namespace std;

const int N = 109;
int n, x, a[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		
		if (a[i] + a[i-1] > 350) {
			cout << 50 << ' ';
		}
		cout << a[i] << ' ';
	}

	return 0;
}
993 删除数组中重复的数
#include 
using namespace std;

int n, x;
set  s;
set  :: iterator it;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> x;
		s.insert(x);
	}
	
	for (it = s.begin(); it != s.end(); it ++) cout << *it << ' ';
	
	return 0;
}
994 删除倍数
#include 
using namespace std;

const int N = 109;
int n, x, a[N];

int main() {
	cin >> n >> x;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		if (a[i] % x != 0) {
			cout << a[i] << ' ';
		}
	}
	
	return 0;
}
995 第K个点
#include 
using namespace std;

const int N = 1009;
int n, k, x;
set  s;
set  :: iterator it;

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i ++) {
		cin >> x;
		s.insert(x);
	}
	
	it = s.begin();
	for (int i = 1; i < k; i ++) it ++;
	cout << *it << endl;
	
	return 0;
}
996 前缀和
#include 
using namespace std;

const int N = 109;
int n, a[N], b[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		b[i] = b[i-1] + a[i];
		cout << b[i] << ' ';
	}
	
	return 0;
}
997 前缀和的逆
#include 
using namespace std;

const int N = 109;
int n, a[N], b[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> b[i];
		a[i] = b[i] - b[i-1];
		cout << a[i] << ' ';
	}
	
	return 0;
}
998 新数列
#include 
using namespace std;

const int N = 109;
int n, a[N], b[N];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	
	for (int i = 1; i <= n; i ++) {
		if (i == 1 || i == n) cout << a[i] << ' ';
		else cout << a[i-1] + a[i] + a[i+1] << ' ';
	}
		
	return 0;
}
999 多次求一段和
#include 
using namespace std;

const int N = 1e5 + 10;
int n, m, a[N], s[N];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		s[i] = s[i-1] + a[i];
	}
	
	while (m --) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		printf("%dn", s[y] - s[x - 1]);
	}
		
	return 0;
}
1000 11的倍数
#include 
using namespace std;

const int N = 1e5 + 10;
int n, m, a[N], s[N];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		s[i] = s[i-1] + a[i];
	}
	
	while (m --) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		
		int t = s[y] - s[x - 1];
		if (t % 11 == 0) puts("1");
		else puts("0");
	}
		
	return 0;
}
1001鸡蛋
#include 
using namespace std;

const int N = 1e5 + 10;
int n, a[N], s[N], h[7];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		s[i] = s[i-1] + a[i];
		h[s[i] % 7] ++;
	}
	
	long long ans = h[0];
	for (int i = 0; i < 7; i ++) {
		ans += h[i] * (h[i] - 1) / 2;
	}
	cout << ans;
			
	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/347439.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号