1、
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int List[1000];
int main(){
    int CaseNumber = 0;
    cin>>CaseNumber;
    while(CaseNumber --){
        int ListNumber = 0;
        cin>>ListNumber;
        int num = 0;
        for(int i = 0; i < ListNumber; i++){
            while(cin >> List[num]){
                if(List[num] == -1){
                    break;
                }else {
                    num ++;
                }
            }
        }
        sort(List, List+num);
        for(int i = 0; i < num; i++){
            cout<<List[i];
            if(i != num -1){
                cout<<" ";
            }
        }cout<<endl;
    }
}
2、
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
char List[1000];
char Father[1000];
int main(){
    int CaseNumber = 0;
    cin>>CaseNumber;
    while(CaseNumber --){
        scanf("%s", List);
        int num = 0;;
        for(int i = 0 ;i  < strlen(List); i++){
            if(List[i] == ‘#‘){
                continue;
            }
            int son = 0;
            if(i *2+1 < strlen(List) && List[i * 2 + 1] !=  ‘#‘){
                son += 1;
            }
            if(i *2+2 < strlen(List) && List[i * 2 + 2] !=  ‘#‘){
                son += 1;
            }
            if(son == 1){
                Father[num++] = List[i];
            }
        }
        cout<<num<<":";
        for(int i = 0 ;i < num; i++){
            cout<<Father[i];
        }
        cout<<endl;
    }
}
/*
1
A#B###C
*/
原文:https://www.cnblogs.com/icodefive/p/10461575.html