1. 程式人生 > 其它 >【C語言學習日誌】【A X A X A 型別中去掉第三個及之後的A】【陣列】

【C語言學習日誌】【A X A X A 型別中去掉第三個及之後的A】【陣列】

技術標籤:C語言學習日誌

一堆卡片,找出其中的重複數字,並按給出的順序排好,最後說出數字是幾,同一數字只出現一次,如果沒有重複數字,要說出“Not Found”。

樣例輸入
7 5 4 3 2 1 2 4
樣例輸出
4 2

解:

#include<stdio.h>
int main()
{
    int m,n,a[100],s=0;
    scanf("%d",&n);
    for(int x=0;x<n;x++)
    {
        scanf("%d",&a[x]);
    }
    for
(int x=0;x<n;x++) { for(int y=x+1;y<n;y++) { if(a[x]==a[y]&&a[x]>=0) { s++; printf("%d ",a[x]); for(int z=y+1;z<n;z++) if(a[z]==a[y]) a[
z]=-1; } } if(s==0&&x==n-1) printf("Not Found"); } return 0; }