1005. 7.2 Printing distinct numbers

来源:互联网 发布:伦纳德数据 编辑:程序博客网 时间:2024/04/30 01:31


Time Limit: 1sec    Memory Limit:256MB
Description

Use pointers on array to write a program that reads in n integers and displays distinct numbers (ie., if a number appears multiple times, it is displayed only once).
 

Input

The first line is a positive integer t for the number of test cases.
Each test case contains two lines. The first line is an integer n (0<n<=100). The second line contains n integers.
 

Output

For each test case, outputs the distinct numbers in order in which they were read, seperated by one blank.
 

Sample Input
 Copy sample input to clipboard
231 2 142 1 2 1
Sample Output
1 22 1

Problem Source: 程序设计I Chapter7 Pointers and C-String

// Problem#: 14320// Submission#: 3675888// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<iostream>using namespace std;int main(){    int T=0,count1=0;    cin>>T;    while(count1<T){                int n;        int count=1;        cin>>n;               int a[100];        int b[100];        for (int i=0; i<100; i++) {            a[i]=0;        }        for (int i=0; i<100; i++) {            b[i]=0;        }        for (int i=0; i<n; i++) {            cin>>a[i];        }        b[0]=a[0];        for (int j=1; j<n; j++) {            bool isY=false;            for (int i=0;i<count; i++) {            if (a[j]==b[i]) {                                isY=true;            }            }            if (isY) {                continue;            }            else{                b[count]=a[j];                count++;            }        }        for (int i=0; i<count-1; i++) {            cout<<b[i]<<" ";        }        cout<<b[count-1]<<endl;                                count1++;    }    return 0;}                                 


conclusion:
Time Limit: 1sec    Memory Limit:256MB
Description

Use pointers on array to write a program that reads in n integers and displays distinct numbers (ie., if a number appears multiple times, it is displayed only once).
 

Input

The first line is a positive integer t for the number of test cases.
Each test case contains two lines. The first line is an integer n (0<n<=100). The second line contains n integers.
 

Output

For each test case, outputs the distinct numbers in order in which they were read, seperated by one blank.
 

Sample Input
 Copy sample input to clipboard
231 2 142 1 2 1
Sample Output
1 22 1

Problem Source: 程序设计I Chapter7 Pointers and C-String

0 0
原创粉丝点击