YTU 2904 Faultfinding解题报告



2904: B--Faultfinding

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 61   Solved: 30
[ Submit][ Status][ Web Board]

Description

Do you remember the game in which we find difference among several similar pictures? Now we change it into digital version. There are N digits, same or different. Please find how many different digits there are among them and output the number.

Input

Each group of the first line is N (1<=N<=10000). The second line consists N integers.

Output

The number of different digits.

Sample Input

2
1 1
3 
1 2 3

Sample Output

1
3



代码:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{

    int n,t;
    int i=0,j=0,k=1;
    int a[10000];
    while(cin>>n)
    {
        while(i<n)
        {
            cin>>a[i];
            i++;

        }
        i=0;
        while(i<n-1)
        {

            while(j<n-i-1)
            {

                if(a[j]>a[j+1])
                {
                    t=a[j];
                    a[j]=a[j+1];
                    a[j+1]=t;
                }
                j++;
            }
            j=0;
            i++;
        }
        i=0,j=0;
        while(i<n-1)
        {

            if(a[i]!=a[i+1])
            {
                k++;
            }
            i++;
        }
        i=0;
        cout<<k<<endl;
        k=1;

    }
    return 0;
}
运行结果:

YTU 2904 Faultfinding解题报告_第1张图片

oj:


解题思路:
对于这种英文题,一定要理解他的意思,大体解释下,先输入一个n代表有多少个数据,然后输出数据中不相同的个数。

首先数据应该用数组储存起来,因为输入进来的数据是杂乱无章的,应该进行排序,这样有利于数据数目的查找,然后用计数器利用循环把不相同的个数记录下来。

最后输出。




你可能感兴趣的:(YTU 2904 Faultfinding解题报告)