Java教程

1083 是否存在相等的差 (20 point(s))

本文主要是介绍1083 是否存在相等的差 (20 point(s)),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

水题 * 3 。

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	map<int, int> ans; 
	cin >> n;
	for(int front = 1; front <= n; front++){
		int contrary;
		cin >> contrary;
		// 计算并存入数组
		ans[abs(front - contrary)]++; 
	}
	for(auto a = ans.rbegin(); a != ans.rend(); a++)
		if(a->second > 1) 
			cout << a->first << " " << a->second << endl;
}
这篇关于1083 是否存在相等的差 (20 point(s))的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!