zoukankan      html  css  js  c++  java
  • HDU 1106 排序

    题目代号:HDU 1106

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1106

    排序

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 60824    Accepted Submission(s): 18013


    Problem Description
    输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。

    你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。

     
    Input
    输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。  

    输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成。
     
    Output
    对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。
     
    Sample Input
    0051231232050775
     
    Sample Output
    0 77 12312320
     
    题目思路:虽然题目很水,我还是WA了好几次,先上几组数据1、开头为5的567589。2、结尾为5的125345。3、中间一大串5的12555598。4、没有5的12346789。
    AC代码:
     1 # include <stdio.h>
     2 # include <string.h>
     3 # include <stdlib.h>
     4 # include <iostream>
     5 # include <fstream>
     6 # include <vector>
     7 # include <queue>
     8 # include <stack>
     9 # include <map>
    10 # include <math.h>
    11 # include <algorithm>
    12 using namespace std;
    13 # define pi acos(-1.0)
    14 # define mem(a,b) memset(a,b,sizeof(a))
    15 # define FOR(i,a,n) for(int i=a; i<=n; ++i)
    16 # define For(i,n,a) for(int i=n; i>=a; --i)
    17 # define FO(i,a,n) for(int i=a; i<n; ++i)
    18 # define Fo(i,n,a) for(int i=n; i>a ;--i)
    19 typedef long long LL;
    20 typedef unsigned long long ULL;
    21 
    22 int a[1005];
    23 char b[1005];
    24 
    25 int main() {
    26   while (~scanf("%s", b)) {
    27     mem(a, 0);
    28     int ans = 0, num = 0, flag = 0;
    29     for (int i = 0; i < strlen(b); i++) {
    30       if (b[i] != '5') {
    31         num = num * 10 + b[i] - '0', flag = 1;
    32       } else if (flag)
    33         a[ans] = num, ans++, num = 0, flag = 0 ;
    34     }
    35     if (b[strlen(b) - 1] != '5')
    36       a[ans] = num, ans++;
    37     sort(a, a + ans);
    38     for (int i = 0, j; i < ans; i++) {
    39       if (i)
    40         cout << ' ';
    41       cout << a[i];
    42     }
    43     puts("");
    44   }
    45   return 0;
    46 }
    View Code
  • 相关阅读:
    linux 删除已输入的命令行
    LAMP编译参数查看
    mysql忘记密码的重置方法
    cmd大全_练习
    Parallel WebDriver executions using TestNG
    Internet Explorer for Mac the Easy Way: Run IE 7, IE8, & IE9 Free in a Virtual Machine
    linux delete files older than 3 days
    5 commands to check memory usage on Linux
    Base64 Encoding / Decoding in Node.js
    10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories
  • 原文地址:https://www.cnblogs.com/teble/p/7224627.html
Copyright © 2011-2022 走看看