Greetings!.
I used 4100 for maximun number of people.
Ah!, and since I used BubbleSort, and got TLE, I used 2 books, one for 'A' to 'L', and one for 'M' to 'Z', and got ACed . You may try QuickSort if you want, but I didn't want to change the sorting
Keep posting!.
struct person
{
char title[20],name[50],lastname[50],adress[70],hphone[20],wphone[20],campusbox[10],department[60];
} dane[250],temp;
void save()
{
strcpy(dane[j].department,dep);
k=0;
for (m=0;;k++,m++)
{
if (os[k]==',') break;
dane[j].title[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].name[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].lastname[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].adress[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].hphone[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==',') break;
dane[j].wphone[m]=os[k];
}
for (m=0,k++;;k++,m++)
{
if (os[k]==0) break;
dane[j].campusbox[m]=os[k];
}
}
void sort_me()
{
j--;
for (k=0;k<=j;k++)
for (m=0;m<j;m++)
{
if (strcmp(dane[m].lastname,dane[m+1].lastname)>0)
{
temp=dane[m];
dane[m]=dane[m+1];
dane[m+1]=temp;
}
}
}
You may have to increase the size of your arrays.. there may be more than 250 people [and each string may or may not be longer than your limits].. there's no limits stated in the problem which kind of sucks having to guess at them..
One useful hint (I got Accepted now this problem):
In input is more than one test case
Best ragards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
int partition(DataStruct *s, int l, int h)
{
int i;
int p;
int firsthigh;
p = h;
firsthigh = l;
for (i=l; i<h; i++)
if (strcmp(s.name,s[p].name)<0){
Swap(&s,&s[firsthigh]);
firsthigh ++;
}
Swap(&s[p],&s[firsthigh]);
return(firsthigh);
}
void qsort(DataStruct *s, int l, int h)
{
int p;
if ((h-l)>0) {
p = partition(s,l,h);
qsort(s,l,p-1);
qsort(s,p+1,h);
}
}
int main()
{
int n,i,j,k;
DataStruct Buffer[80];
char buff[4200],*temp,department[4000];
scanf("%d\n",&n);
k=0;
while (gets(buff)){
strcpy(department,buff);
while (temp=gets(buff)){
if (strlen(buff)==0)break;
strcpy(Buffer[k].department,department);
i=0;j=0;
while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=' ';++i;
while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=' ';++i;
while (buff!=','){
Buffer[k].name[j++]=buff[i++];
}
Buffer[k].name[j++]=0;++i;
j=0;
while (buff!=','){
Buffer[k].country[j++]=buff[i++];
}
Buffer[k].country[j++]=0;++i;
j=0;
while (buff!=','){
Buffer[k].homephone[j++]=buff[i++];
}
Buffer[k].homephone[j++]=0;++i;
j=0;
while (buff!=','){
Buffer[k].workphone[j++]=buff[i++];
}
Buffer[k].workphone[j++]=0;++i;
j=0;
while (buff){
Buffer[k].campusbox[j++]=buff[i++];
}
Buffer[k].campusbox[j++]=0;++i;
++k;
}
if (temp==0)break;
}