首页
学习
活动
专区
圈层
工具
发布
29 篇文章
1
PAT (Basic Level) Practice (中文)1047 编程团体赛
2
PAT (Basic Level) Practice (中文)1083 是否存在相等的差
3
PAT (Basic Level) Practice (中文)1082 射击比赛
4
PAT (Basic Level) Practice (中文)1081 检查密码
5
PAT (Basic Level) Practice (中文)1077 互评成绩计算
6
PAT (Basic Level) Practice (中文)1076 Wifi密码
7
PAT (Basic Level) Practice (中文)1064 朋友数
8
PAT (Basic Level) Practice (中文)1063 计算谱半径
9
PAT (Basic Level) Practice (中文)1057 数零壹
10
PAT (Basic Level) Practice (中文)1056 组合数的和
11
PAT (Basic Level) Practice (中文)1042 字符统计
12
PAT (Basic Level) Practice (中文)1041 考试座位号
13
PAT (Basic Level) Practice (中文)1023 组个最小数
14
PAT (Basic Level) Practice (中文)1022 D进制的A+B
15
PAT (Basic Level) Practice (中文)1019 数字黑洞
16
PAT (Basic Level) Practice (中文)1007 素数对猜想
17
PAT (Basic Level) Practice (中文)1091 N-自守数
18
PAT (Basic Level) Practice (中文)1026 程序运行时间
19
PAT (Basic Level) Practice (中文)1061 判断题
20
PAT (Basic Level) Practice (中文)1086 就不告诉你
21
PAT (Basic Level) Practice (中文)1016 部分A+B
22
PAT (Basic Level) Practice (中文)1012 数字分类
23
PAT (Basic Level) Practice (中文)1013 数素数
24
PAT (Basic Level) Practice (中文)1011 A+B 和 C
25
PAT (Basic Level) Practice (中文)1009 说反话
26
PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题
27
PAT (Basic Level) Practice (中文)1006 换个格式输出整数
28
PAT (Basic Level) Practice (中文)1004 成绩排名
29
PAT (Basic Level) Practice (中文)1002 写出这个数

PAT (Basic Level) Practice (中文)1083 是否存在相等的差

1083 是否存在相等的差

给定 N 张卡片,正面分别写上 1、2、……、N,然后全部翻面,洗牌,在背面分别写上 1、2、……、N。将每张牌的正反两面数字相减(大减小),得到 N 个非负差值,其中是否存在相等的差?

输入格式:

输入第一行给出一个正整数 N(2 ≤ N ≤ 10 000),随后一行给出 1 到 N 的一个洗牌后的排列,第 i 个数表示正面写了 i 的那张卡片背面的数字。

输出格式:

按照“差值 重复次数”的格式从大到小输出重复的差值及其重复的次数,每行输出一个结果。

输入样例:

8 3 5 8 6 2 1 4 7

输出样例:

5 2 3 3 2 2

代码:

代码语言:javascript
复制
#include<stdio.h>
#include<math.h>
int main()
{
    int N;
    scanf("%d",&N);
    int i;
    int n;
    int arr[10001]={0};
    for(i=0;i<N;i++)
    {
        scanf("%d",&n);
        arr[(int)fabs(n-(i+1))]++;
    }
    for(i=N-1;i>=0;i--)
    {
        if(arr[i]>1)
            printf("%d %d\n",i,arr[i]);
    }
    return 0;
}
下一篇
举报
领券