我是靠谱客的博主 舒服乌冬面,最近开发中收集的这篇文章主要介绍1005. 7.2 Printing distinct numbers,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述



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
2
3
1 2 1
4
2 1 2 1
Sample Output
1 2
2 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
2
3
1 2 1
4
2 1 2 1
Sample Output
1 2
2 1

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

最后

以上就是舒服乌冬面为你收集整理的1005. 7.2 Printing distinct numbers的全部内容,希望文章能够帮你解决1005. 7.2 Printing distinct numbers所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部