CPP 1373 Easy as A+B(冒泡排序)

题目链接: http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1373

题面:

Easy as A+B

Time Limit:1000MS  Memory Limit:32768K

Description:

These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights. Give you some integers, your task is to sort these number ascending. You should know
how easy the problem is now! Good luck!

Input:

Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in
the same line. It is guarantied that all integers are in the range of 32bit-int.

Output:

For each case, print the sorting result, and one line one case.

Sample Input:

2
3 2 1 3
9 1 4 7 2 5 8 3 6 9

Sample Output:

1 2 3
1 2 3 4 5 6 7 8 9

Source:

lcy

题解:

冒泡排序一下,套了下别人写的,居然是错的,以后还是自己写吧。

代码:

#include <stdio.h>
int main()
{
  int temp,t,n;
  int store[1005];
  scanf("%d",&t);
  while(t--)
  {
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf ("%d,",&store[i]);
    for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    if (store[i] > store[j])
                    {
                        temp = store[i];
                        store[i] = store[j];
                        store[j] = temp;
                    }
                }
            }
    printf("%d",store[0]);
    for(int i=1;i<n;i++)
      printf(" %d",store[i] );
    printf("\n");
  }
  return 0;
}
时间: 2024-08-03 00:49:26

CPP 1373 Easy as A+B(冒泡排序)的相关文章

YZOI Easy Round 2_化简(simplify.c/cpp/pas)

Description 给定一个多项式,输出其化简后的结果. Input 一个字符串,只含有关于字母x 的多项式,不含括号与分式,没有多余的空格. Output 一个字符串,化简后的多项式,按照次数从大到小的顺序输出各项. Input Sample x^3+3*x^4-2*x^3+1-x Output Sample 3*x^4-x^3-x+1 Hint 每项系数<10,次数<6,项数<20.字符串长度不超过100. 很烦的模拟   代码如下: #include<iostream&g

冒泡排序 cpp实现

#include<bits/stdc++.h> using namespace std; void Bubblesort(int a[],int n){ for(int i=0;i<n-1;i++){ int flag = 0; for(int j=0;j<n-i-1;++j){ //注意内层是n-i-1就行 if(a[j]>a[j+1]){ int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; flag=1; //发生交换,改变flag值 } i

C语言中的排序算法--冒泡排序,选择排序,希尔排序

冒泡排序(Bubble Sort,台湾译为:泡沫排序或气泡排序)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成.这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端 维基百科:点击打开链接 [cpp] view plain copy /* 用选择法对10个数进行排序 */ #include<stdio.h> void main() { int i,j,

Identify Memory Leaks in Visual CPP Applications(VLD内存泄漏检测工具)

原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于CPOL License Identify Memory Leaks in Visual CPP Applications Visual Leak Detector (VLD) is an easy to use memory leak detection system. The installat

HDU 4565 So Easy! 矩阵快速幂 + 共轭数

题意:中文题 So Easy 解题思路: 这题应该是 HDU 2256的原题 , 根据类似的结论可以推出 中间矩阵 ta  1 tb ta 原矩阵 1 1 解题代码: 1 // File Name: temp.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月17日 星期三 11时35分45秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #inc

白话经典算法系列之中的一个 冒泡排序的三种实现

冒泡排序是很easy理解和实现,,以从小到大排序举例: 设数组长度为N. 1.比較相邻的前后二个数据,假设前面数据大于后面的数据,就将二个数据交换. 2.这样对数组的第0个数据到N-1个数据进行一次遍历后,最大的一个数据就"沉"到数组第N-1个位置. 3.N=N-1,假设N不为0就反复前面二步,否则排序完毕. 依照定义非常easy写出代码: //冒泡排序1 void BubbleSort1(int a[], int n) { int i, j; for (i = 0; i < n

(DS 《算法入门经典》)UVA 11991 Easy Problem from Rujia Liu?(求第k个v出现的索引)

题目大意: 求第k个v出现的索引 解题思路: 如果能构造出一个数据结构,使得data[v][k]就是第k个v出现的索引值即可求解.data[v]表示数v出现的索引数组, data[v][k]表示第k个v出现的索引. Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 200

冒泡排序的三种实现

冒泡排序是非常容易理解和实现,,以从小到大排序举例: 设数组长度为N. 1.比较相邻的前后二个数据,如果前面数据大于后面的数据,就将二个数据交换. 2.这样对数组的第0个数据到N-1个数据进行一次遍历后,最大的一个数据就“沉”到数组第N-1个位置. 3.N=N-1,如果N不为0就重复前面二步,否则排序完成. 按照定义很容易写出代码: [cpp] view plain copy //冒泡排序1 void BubbleSort1(int a[], int n) { int i, j; for (i 

插入排序、冒泡排序、选择排序、希尔排序、快速排序、归并排序、堆排序和LST基数排序——C++实现

首先是算法实现文件Sort.h,代码如下: /* * 实现了八个常用的排序算法:插入排序.冒泡排序.选择排序.希尔排序 * 以及快速排序.归并排序.堆排序和LST基数排序 * @author gkh178 */ #include <iostream> template<class T> void swap_value(T &a, T &b) { T temp = a; a = b; b = temp; } //插入排序:时间复杂度o(n^2) template<