当前位置:网站首页>Find the card with equal difference (20 points) C language
Find the card with equal difference (20 points) C language
2022-04-21 18:18:00 【Big dish color】
Find cards with equal differences (20 branch )
Given N Cards , Write... On the front 1、2、……、N, Then turn it all over and shuffle , Still arranged face down , Write... On the back 1、2、……、N. Subtract the numbers on both sides of each card ( Greatly reduced ), obtain N A nonnegative difference , Find the card with the same difference .
Input format :
The first line of input gives a positive integer N(2 ≤ N ≤ 10 000), The next line shows 1 To N A shuffled arrangement of , The first i The number indicates that it is written on the front i The number on the back of the card .
Output format :
Output the repeated difference and the number of repetitions according to the difference from large to small , The format is :
Difference value Repeat the number
Output one result per line .
sample input :
Here's a set of inputs . for example :
8
3 5 8 6 2 1 4 7
sample output :
Here is the corresponding output . for example :
5 2
3 3
2 2
Code :
#include<stdio.h>
int main()
{
int n,i,j,a[10001],b[10001]={
0};
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if((i+1)>=a[i]) // The number on the front is greater than or equal to the number on the back
b[(i+1)-a[i]]++; // Save the difference in the following form b Array
else // The number on the back is greater than or equal to the number on the front
b[a[i]-(i+1)]++;
}
for(i=10001;i>=0;i--) // Go back and forth b Array It's just the difference from big to small
if((b[i]!=0)&&(b[i]!=1)) // Find duplicate
printf("%d %d\n",i,b[i]); //i It's the difference b[i] It's the number of times
return 0;
}
Submit results :

版权声明
本文为[Big dish color]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211816371812.html
边栏推荐
猜你喜欢

Don't look for it. This is the clearest article on microservices so far! No one

靶机渗透练习70-DC2

Target penetration exercise 70-dc2

单例模式你不得不知道的底层原理

Target penetration exercise 76-dc8

Target penetration exercise 74-dc6

Target penetration exercise 73-dc5

You must understand and can understand microservice series 3: service invocation

Target penetration exercise 75-dc7

WPF learning notes - Overview
随机推荐
fastjson自动升级成fastjson2后 IDEA开发环境正常 打成jar包发布生成环境后报错异常 pom.xml的version自动升级导致
A common CommonDialog
ES6新特性(1)之let命令/const命令/解构赋值/Symbol/Set/WeakSet
In order to offer several big factories, "closed door practice"
Q: Making line chart with Excel
Composant tooltip: déterminer si tooltip est affiché en fonction du débordement de contenu
干货 | 读懂 Appium 日志,让测试效率翻倍!
Porting openharmony and adding WiFi driver
为什么switch里的case没有break不行
CDF全球调查:软件交付性能停滞不前
Q:excel制作折线图
Tooltip 组件:根据内容是否溢出判断是否显示 Tooltip
WPF RichTextBox赋值与取值
再见SharedPreferences,你好MMKV!
How can the manufacturing industry save itself under the crisis of insufficient personnel and broken supply chain?
最基本的JDBC模板及数据库乱码处理
MySQL 8.0远程连接2059异常
【NPJ|数字医药】医学影像的机器学习:方法学的失败和对未来的建议
Huawei cloud gaussdb (for influx) unveiling phase VI - hierarchical data storage
WPF learning notes - Overview