非法功能,Spotify 技术难题

发布于 2024-12-12 03:38:15 字数 3459 浏览 0 评论 0原文

我正在尝试解决此处找到的 Spotify 难题“双边”: http:// www.spotify.com/us/jobs/tech/bilingual-projects/

我已经对我的程序进行了一系列测试,我似乎得到了正确的输出,但是在提交后,拼图法官告诉我“非法的 功能”。

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

#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;   
}

I am trying to solve the Spotify Puzzle 'Bilateral' found here: http://www.spotify.com/us/jobs/tech/bilateral-projects/

I have run a bunch of tests on my program and I seem to get the correct output, however upon submitting it, the Puzzle Judge tells me "Illegal Function".

I was wondering if someone would look at my code and see if anything looks like it could be causing this error.

#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;   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2024-12-19 03:38:15

对我来说唯一可疑的是:

system("PAUSE");

也许 Spotify 并不希望您的程序在完成后暂停。

The only thing suspicious to me is:

system("PAUSE");

Maybe spotify doesnt expect your program to pause once it completes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文