adjacent difference
来源:互联网 发布:何凯文和田静语法知乎 编辑:程序博客网 时间:2024/05/22 08:03
#include <iostream>
using namespace::std;
int main()
{
int m,n,i,l=1,a[1001]={0},b[1001]={0};
cin >> m;
while(m--)
{
cin >> n;
for(i=1;i<=n;i++)
cin >> a[i];
for(i=1;i<=n;i++)
b[i]=a[i]-a[i-1];
sort(b+1,b+n+1);
cout << "Case " << l++ << ":" << '\n';
for(i=1;i<=n;i++)
{
if(i>1)
cout << " ";
cout << b[i];
}
cout << '\n';
}
}
/*
Problem 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 2^16), 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 1. 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
1
5
1 3 2 4 5
Sample Output
Case 1:
-1 1 1 2 2
*/
- adjacent difference
- WOJ1020-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>注意
- 如何学习一门新的编程语言?——在学习区刻意练习
- 置换排列
- 计算机信息存储单位,数制编码总结
- Runnable 和 Thread
- MS SQL Server 2008 master数据库损坏故障解决
- adjacent difference
- Java反编译工具Java Decompiler
- Java编译原理
- Win7使用初体验
- 开发者必备的6款源码搜索引擎
- toString() ,String,String.valueOf
- FBI树
- ActionBar, android 各版本的新特性
- JVM的基本工作原理和特点