不明白1514

/*
Your school organized a big party to celebrate your team brilliant win in the prestigious, worldfamous ICPC (International Collegiate Poetry Contest). Everyone in your school was invited for an evening which included cocktail, dinner and a session where your team work was read to the audience. The evening was a success - many more people than you expected showed interested in your poetry - although some critics of yours said it was food rather than words that attracted such an audience.

  Whatever the reason, the next day you found out why the school hall had seemed so full: the school director confided he had discovered that several of the tickets used by the guests were fake. The real tickets were numbered sequentially from 1 to N (N <= 10000). The director suspects some people had used the school scanner and printer from the Computer Room to produce copies of the real tickets. The director gave you a pack with all tickets collected from the guests at the party's entrance, and asked you to determine how many tickets in the pack had 'clones', that is, another ticket with the same sequence number.
  
    
      Input
      
        The input contains data for several test cases. Each test case has two lines. The first line contains two integers N and M which indicate respectively the number of original tickets and the number of persons attending the party (1 <= N <= 10000 and 1 <= M <= 20000). The second line of a test case contains M integers Ti representing the ticket numbers in the pack the director gave you (1 <= Ti <= N). The end of input is indicated by N = M = 0.
        
          
            Output
            
              For each test case your program should print one line, containing the number of tickets in the pack that had another ticket with the same sequence number. 
              
                
                  Sample Input
                  
                    5 5
                    3 3 1 2 4
                    6 10
                    6 1 3 6 6 4 2 3 1 2
                    0 0
                    
                      
                        Sample Output
                        
                          1
                          4
                          
                            
                              
*/

#include 
< iostream.h >
#include 
< malloc.h >
// #define MAX 10000

int  main()
{
//     int array[MAX];
     int  position = 0 ;
    
int  N,M;
    
int  i,j;
    
int  count = 0 ;
    cin
>> N;
    cin
>> M;
    
int   * temp, * right_temp;
    
while  (N)
    {
        count
= 0 ;
        temp
= ( int   * )malloc( sizeof ( int ) * M);
        
for  (i = 0 ;i < M;i ++ )
        {
            cin
>>* (temp + i);
        }
        
for  (i = 0 ;i < (M - 1 );i ++ )
        {
            
for  (j = (i + 1 );j < M;j ++ )
            {
                
if  ( * (temp + i)  &&   * (temp + j)  &&  (( * (temp + i)) == ( * (temp + j))))
                {
                    
* (temp + i) = 0 ;
                    
* (temp + j) = 0 ;
                    count
++ ;
                }
            }
        }
        delete []temp;
        cout
<< count << endl;
    
//     array[position++]=count;
        cin >> N;
        cin
>> M;
    }
    
/*
    for (i=0;i<position;i++)
    {
        cout<<array[i]<<endl;
    }
    
*/
    
return   0 ;
}

 

 

 

#include < iostream >
#include
< cmath >
using   namespace  std;
int  main()
{
 
int  N,M,i,j,tmp,count = 0 ,b;
 
int  a[ 20000 ];
 cin
>> N >> M;
 
while (N != 0 )
 {
  
for (i = 0 ;i < M;i ++ )
  {
   cin
>> a[i];
  }
  
for (i = 0 ;i < M - 1 ;i ++ )
  {
   
for (j = i + 1 ;j < M;j ++ )
   {
    
if (a[i] > a[j])
    {
     tmp
= a[i];
     a[i]
= a[j];
     a[j]
= tmp;
    }
   }
  }
  b
=- 1 ;
  
for (i = 0 ;i < M;i ++ )
  {
   
if (a[i] == a[i + 1 ])
   {
    
if (a[i + 1 ] != b)
     count
++ ;
    b
= a[i];
   }
  }
  cout
<< count << endl;
  b
=- 1 ;
  count
= 0 ;
  cin
>> N >> M;
 }
 
return   0 ;
}

上面的代码的功能都是一样的,为什么第二个可以AC,但是第一个就不行了,而且还是WRONG ANSWER。 有时间要好好看看.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值