非法功能,Spotify技术难题

时间:2011-10-26 22:16:37

标签: c++ spotify

我正在尝试解决这里发现的Spotify拼图'双边':http://www.spotify.com/us/jobs/tech/bilateral-projects/

我已对我的程序运行了一系列测试,我似乎得到了正确的输出,但是在提交时,Puzzle Judge告诉我“非法功能”。

我想知道是否有人会查看我的代码并查看是否有任何内容可能导致此错误。

#include <cstdlib>
#include <iostream>

using namespace std;
struct idnumber
{
  int num;
  int count;      
};
struct team
{
       int id1;
       int id2;
};
void solve(team *team, int size);
bool duplicate(idnumber id1, idnumber id2[], int size);


int main(int argc, char *argv[])
{
   int m=0; 
   string input;
   team * teams;
   cout<<"Number of teams: ";
   while(!(cin >> m) || cin.peek() != '\n' || m < 1 || m > 10000)
            {
                cout << "\n\nPlease enter a valid number of teams: ";
                cin.clear();
                cin.ignore();            
            }
   cin.clear();
   cin.ignore();
   teams = new team[m];
   for (int i=0;i<m;i++)
   {
       cout<<"IDs for team " <<i+1 <<": ";
       cin >> teams[i].id1;
       cin >> teams[i].id2;

   }
    solve(teams, m);
    delete teams;
    system("PAUSE");
    return EXIT_SUCCESS;
}

void solve(team *teams,int size)
{
     int p=0,j=0, size2 = size*2, tempnum=size,count=0;
     idnumber stockholm[size],london[size],tempid,tempid2[size],idlist[size2],id[size2];
     const int FRIEND = 1009;

     int temp[size],temp2[size];

     for (p=0;p<size;p++)
     {
        stockholm[p].num = teams[p].id1;
        stockholm[p].count = 0;
        london[p].num = teams[p].id2;
        london[p].count = 0;
     }

     for (p=0;p<size;p++)
     {
         temp[p] = stockholm[p].num;
         temp2[p] = london[p].num;
     }

     for (p=0;p<size;p++)
     {
        for(j=0;j<size;j++)
        {
            if (stockholm[p].num ==  temp[j])
               stockholm[p].count++;   

            if (london[p].num ==  temp2[j])
               london[p].count++;                 
        }   
     }

     for(p=0;p<size;p++)
     {
        id[p] = stockholm[p];
        id[p+size] =  london[p];               
     }

     for(p=0;p<=size2;p++)
     { 
        for(j=0;j<size2-1;j++)
        {
           if(id[j+1].count > id[j].count || ((id[j+1].count == id[j].count) && (id[j+1].num == FRIEND)))
           { 
              tempid = id[j];
              id[j] = id[j+1];
              id[j+1] = tempid;
           }
        }                 
     }

     for(p=0;p<size2;p++)
     {
        idlist[p].count = 0;
        idlist[p].num = 9999;    
     }

     for(p=0;p<size2;p++)
     {
           if(!duplicate(id[p], idlist, size2))
           {
              if(count<size2)
              {
                 idlist[count] = id[p];
                 count++;
              }
           }                    
     }
     for(p=0;p<size2;p++)
      count=0;
      while(tempnum > 0)
      {
          tempnum -= idlist[count].count;
          count++;          
      }

      cout<<count<<"\n";
      for(p=0;p<count;p++)
        cout<<idlist[p].num<<"\n";
}


bool duplicate(idnumber id1, idnumber id2[], int size)
{ 
  bool flag = false;
  for(int i=0;i<size;i++)
  {
     if(id1.num == id2[i].num)
     {                     
        flag = true;
     }
     if(flag)
       break;
  }
  return flag;   
}

1 个答案:

答案 0 :(得分:1)

对我来说唯一可疑的是:

系统( “暂停”);

也许spotify并不期望你的程序一旦完成就会暂停。