WOJ1020-Adjacent Difference
来源:互联网 发布:windows syslog服务器 编辑:程序博客网 时间:2024/05/16 14:01
Description
An adjacent difference of a sequence is a new sequence formed by replacing every element with the difference between the element and
the immediately preceding element. The first value in the new sequence remains unchanged. For example, a sequence such as (1, 3, 2, 4, 5)
is transformed into (1, 3-1,2-3, 4-2, 5-4), and in this manner becomes the sequence (1, 2, -1, 2, 1). Then, we want to sort the adjacent
difference of the sequence in non-decreasing order. It?s an easy job for you, isn?t it? So, please solve it quickly.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T(1 <= T <= 50) which is the number of
test cases.
For each test case, the first line contains an integer N(1 <= N <= 1000), representing the size of the sequence. The second line contains N integers (you are ensured that the absolute value of each integer is less than ), representing the elements of this sequence.
Output
Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from
- Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, output one line containing n elements representing the sorted adjacent difference of the sequence. Elements are separated by one blank space.
Sample Input
151 3 2 4 5
Sample Output
Case 1:-1 1 1 2 2
#include<stdio.h>#include<stdlib.h>int in[1005],out[1005];int comp(const void*a,const void*b){return *(int*)a-*(int*)b;}int main(){int t,n,i,j;scanf("%d",&t);for(i=0;i<t;i++){scanf("%d",&n);for(j=0;j<n;j++){scanf("%d",&in[j]);}for(j=0;j<n;j++){if(j==0)out[0]=in[0];elseout[j]=in[j]-in[j-1];}qsort(out,n,sizeof(int),comp);printf("Case %d:\n",i+1);for(j=0;j<n;j++){printf("%d",out[j]);if(j!=n-1)printf(" "); }if(i!=t-1)printf("\n\n");}}
- WOJ1020-Adjacent Difference
- adjacent difference
- WOJ:Problem 1020 - Adjacent Difference
- 4-adjacent
- Practice_5: Adjacent List Graph
- Sicily 4421. Adjacent Rooms
- Adjacent Bit Counts(P3786)
- Adjacent Bit Counts
- Adjacent Bit Counts
- 【nyoj715】Adjacent Bit Counts
- nyoj 715 Adjacent Bit Counts
- [GeeksforGeeks]Remove all adjacent duplicates
- NYOJ 715 Adjacent Bit Counts
- SPOJ 5295 Adjacent Bit Counts
- Adjacent Bit Counts (DP)
- NYOJ 715 Adjacent Bit Counts
- implement a undirected graph use adjacent list
- 使用DELETE ADJACENT DUPLICATES FROM <table>注意
- 配置VIRL时,关于ntp的巨坑
- linux常考命令之grep
- C++ 生牛递归问题
- 2017年(成都)第96届全国(春季)糖酒商品交易会会刊(参展商名录)
- printf相关函数
- WOJ1020-Adjacent Difference
- 稀疏线性回归(lp正则)
- 修改 thinkphp5 分页样式
- ES搜索性能优化
- windows下python3.5安装opencv相关包
- 深入理解高并发程序设计
- 如何显示JVM(JAVA虚拟机)类加载顺序
- 1044. 火星数字(20)
- CDH 删除 角色