1005. 7.2 Printing distinct numbers
来源:互联网 发布:伦纳德数据 编辑:程序博客网 时间:2024/04/30 01:31
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).
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.
For each test case, outputs the distinct numbers in order in which they were read, seperated by one blank.
231 2 142 1 2 1
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;}
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).
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.
For each test case, outputs the distinct numbers in order in which they were read, seperated by one blank.
231 2 142 1 2 1
1 22 1
Problem Source: 程序设计I Chapter7 Pointers and C-String
- 1005. 7.2 Printing distinct numbers
- Printing ALV along with Page numbers
- Java (printing numbers in a pyramid pattern)
- Printing numbers in a pyramid pattern(一)
- Exercise 9: Printing, Printing ,Printing
- Exercise 8: Printing ,Printing
- distinct
- Distinct
- distinct
- distinct
- distinct
- distinct
- distinct
- distinct
- distinct
- distinct
- distinct
- DISTINCT
- Rcurl抓取NCBI信息
- 使用Java实现双缓冲绘图
- Remove Linked List Elements
- [LeetCode] Add and Search Word - Data structure design
- LeetCode解题报告--Longest Palindromic Substring
- 1005. 7.2 Printing distinct numbers
- Android 判断手机是否联网时异常闪退
- 威威猫系列故事——打地鼠(HDU-4540)
- Triangle -- leetcode
- Cocosd-x(3.4版本)移植Android平台
- java的反射类讲解
- Android笔记2——Android的用户界面1
- Animation 动画详解(一)——alpha、scale、translate、rotate、set的xml属性及用法
- 1003. Sorting