11239 - Open Source

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

11239 - Open Source

Post by SHAHADAT » Sun Jul 15, 2007 3:38 am

i donot know whats wrong with the code

can any one please tell me?
i have tried many input and output .
but got the correct output.
but the judge solution does not like it.
whY?

code removed after got ac------->

sorry it was a silly mistake that should not have done during the contest time.
I have to do code more carefully.
thanks all.
sorry for my poor english :D
-----------------------------------------------------------------
LIFE IS COMBINED WITH JOY AND SORROW.IT IS NOT ONLY FOR SITTING IN A ROOM AND TYPING CODE.
Last edited by SHAHADAT on Tue Jul 31, 2007 4:00 pm, edited 4 times in total.

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish » Sun Jul 15, 2007 4:11 am

Try this case
input

Code: Select all

A
x
x
x
B
x
x
x
C
x
x
x
1
0
output

Code: Select all

A 0
B 0
C 0
Hope this helps.

darkos32
New poster
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia
Contact:

asd

Post by darkos32 » Sun Jul 15, 2007 7:25 am

i've also got WA..can anyone give me testcases ?

thanks...

User avatar
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

Post by Rocky » Sun Jul 15, 2007 7:47 am

to darkos32:
Do u try mmonish test case..????

try with some more:

input

Code: Select all

A 
x 
c 
B 
x 
C 
1 
A 
B 
C 
1 
output

Code: Select all

A 1 
B 0 
C 0 
A 0 
B 0 
C 0 

oh..yes there is no information about the length of the project name and student name....check it.

GOOD LUCK
Rocky

darkos32
New poster
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia
Contact:

asd

Post by darkos32 » Sun Jul 15, 2007 7:57 am

i've try it and still got WA...btw,how long the information would be ?i use 100 chars..


this is my code :

Code: Select all

#include <stdio.h>
#include <string.h>
int max,maxmurid,maxpr[101],posmurid[101];
char murid[10001][100],projek[101][100];


void sort(){
	for(int i=0;i<max;i++){
		for(int j=i+1;j<max;j++){
			if(maxpr[i]<maxpr[j]){
				char temp[100];
				strcpy(temp,projek[i]);
				strcpy(projek[i],projek[j]);
				strcpy(projek[j],temp);
				int temps = maxpr[i];
				maxpr[i] = maxpr[j];
				maxpr[j] = temps;
			}
			else if(maxpr[i]==maxpr[j] && strcmp(projek[i],projek[j])>0){
				char temp[100];
				strcpy(temp,projek[i]);
				strcpy(projek[i],projek[j]);
				strcpy(projek[j],temp);
				int temps = maxpr[i];
				maxpr[i] = maxpr[j];
				maxpr[j] = temps;
			}
		}
	}
}

void main(){
	freopen("11239.in","r",stdin);
	freopen("11239.out","w",stdout);
	char s[100];
	max = 0;
	maxmurid = 0;
	while(gets(s)){
		if(strcmp(s,"1")==0) {
			sort();
			for(int i=0;i<max;i++){
				printf("%s %d\n",projek[i],maxpr[i]);
			}
			max=0;
			maxmurid = 0;
			continue;
		}
		if(strcmp(s,"0")==0) {
			break;
		}
		if(s[0]>='0' && s[0]<='9') continue;
		if(s[0]>='A' && s[0]<='Z'){
			strcpy(projek[max],s);
			maxpr[max] = 0;
			max++;
		}
		if(s[0]>='a' && s[0]<='z' && max>0){
			bool ada= false;
			for(int i=0;i<maxmurid && !ada;i++){
				if(strcmp(murid[i],s)==0){
					if(posmurid[i]!=max-1 && posmurid[i]!=-1){
						maxpr[posmurid[i]]--;
						posmurid[i] = -1;
					}
					ada = true;
				}
			}
			if(ada) continue;
			strcpy(murid[maxmurid],s);
			posmurid[maxmurid] = max-1;
			maxmurid++;
			maxpr[max-1]++;
		}
	}
}


thanks..

rushel
Learning poster
Posts: 67
Joined: Sat Jan 22, 2005 5:57 am

Post by rushel » Sun Jul 15, 2007 10:11 am

I think use of STL will simplify things

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

Post by SHAHADAT » Sun Jul 15, 2007 10:48 am

to darkos32
i tested that the char array is enough with size murid[10001][20]
donot worry abt it.

check this segment of code again

Code: Select all

if(posmurid[i]!=max-1 && posmurid[i]!=-1){
-----------------------------------------------------------------
LIFE IS COMBINED WITH JOY AND SORROW.IT IS NOT ONLY FOR SITTING IN A ROOM AND TYPING CODE.
Last edited by SHAHADAT on Tue Jul 31, 2007 3:59 pm, edited 1 time in total.

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am

Post by hamedv » Sun Jul 15, 2007 10:11 pm

what's the bug of my code???

Code: Select all

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

string list[10005];
int list_n = 0;
int p2[14];

void list_init()
{
	int i;
	for (p2[0] = 1,i = 1; i < 14; i++) p2[i] = 2*p2[i-1];
}

void add(string s)
{
	list[list_n++] = s;
	sort(list, list+list_n);
}

bool is_there(string s)
{
	int index = 0, i;
	for (i = 0; i < list_n; i++)
		if (list[i] == s) return 1;1;
	add(s);
	return 0;
}

string line()
{
	char c;
	string s = "";
	while ((c = getchar()) != '\n') s += c;
	return s;
}


string project, stuname;
int students, n, i, j;
string project_list_name[105];
int project_list_num[105];

void swap(int i)
{
	int n;
	string s;
	n = project_list_num[i];
	project_list_num[i] = project_list_num[i+1];
	project_list_num[i+1] = n;
	s = project_list_name[i];
	project_list_name[i] = project_list_name[i+1];
	project_list_name[i+1] = s;
}

int main()
{
	list_init();
	while ((project = line()) != "0")
	{
		n = 0;
		list_n = 0;
		do {
			students = 0;
			while (((stuname = line()) != "") && (stuname[0] <= 'z' && stuname[0] >= 'a')) 
				if (!is_there(stuname))
					puts("No"), students++; else puts("Yes");
			project_list_name[n] = project;
			project_list_num[n++] = students;
		} while ((project = stuname) != "1");
		for (i = 0; i < n-1; i++)
			for (j = 0; j < n-1; j++)
				if (project_list_num[i] < project_list_num[i+1])
					swap(i);
		for (i = 0; i < n-1; i++)
			for (j = 0; j < n-1; j++)
				if ((project_list_num[i] == project_list_num[i+1]) && (project_list_name[i] > project_list_name[i+1]))
					swap(i);
		for (i = 0; i < n; i++)
			cout << project_list_name[i] << " " << project_list_num[i] << endl;
	}
}

David Kjaer
New poster
Posts: 9
Joined: Sat Jul 07, 2007 5:47 pm
Location: Denmark

Post by David Kjaer » Tue Jul 17, 2007 5:22 am

Read the roject statement carefully...

It says, approximately "if a student signs up for two different courses, he participates in neither", but a student might be listed twice on a project but then he only counts once...

And a little hint: Use sets...
Randers FC l

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am

Post by hamedv » Sun Jul 22, 2007 4:33 pm

i changech my code to :

Code: Select all

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <set>

using namespace std;

struct project {
	string name;
	set<string> student;
	int num;
};

struct tot {
	string name[10010];
	int n[10010], i;
};

string getstring()
{
	char s[100];
	gets(s);
	string r = s;
	return r;
}

tot list;

void inc(string s)
{
	for (int j = 0; j < list.i; j++)
		if (list.name[j] == s)
		{
			list.n[j]++;
			return;
		}
	list.name[list.i] = s;
	list.n[list.i] = 1;
	list.i++;
}

int pos(string s)
{
	for (int i = 0; i < list.i; i++)
		if (list.name[i] == s)
			return i;
}

int main()
{
	string name, pr;
	project p[110], tmp;
	int pi, i, j, t;
	while ((pr = getstring()) != "0")
	{
		list.i = 0;
		pi = 0;
		do {
			p[pi].name = pr;
			p[pi].student.clear(); 
			while (((name = getstring()) != "") && (name[0] <= 'z' && name[0] >= 'a'))
			{
				t = p[pi].student.size();
				p[pi].student.insert(name);
				if (t < p[pi].student.size()) inc(name);
			}
			pi++;
		} while ((pr = name) != "1");
		set<string>::iterator it;
		for (i = 0; i < pi; i++)
		{
			p[i].num = p[i].student.size();
			for (it = p[i].student.begin(); it != p[i].student.end(); ++it)
				if (list.n[pos(*it)] != 1)
					p[i].num--;
		}
		for (i = 0; i < pi-1; i++)
			for (j = 0; j < pi-1; j++)
				if (p[j].student.size() < p[j+1].student.size())
				{
					tmp = p[j];
					p[j] = p[j+1];
					p[j+1] = tmp;
				}
		for (i = 0; i < pi-1; i++)
			for (j = 0; j < pi-1; j++)
				if ((p[j].student.size() == p[j+1].student.size()) && (p[j].name > p[j+1].name))
				{
					tmp = p[j];
					p[j] = p[j+1];
					p[j+1] = tmp;
				}
		for (i = 0; i < pi; i++)
			cout << p[i].name << " " << p[i].num << endl;
	}
}

but i'm getting wa :cry:

zhj5825
New poster
Posts: 1
Joined: Thu Jul 26, 2007 7:27 pm

Post by zhj5825 » Thu Jul 26, 2007 7:32 pm

I found the test data in the waterloo web-site, and compared my output with the judge output, they are all the same! But I still got WA here. I don't know why... Can somebody help me out? Thanks very much~

Code: Select all

#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

typedef struct ans
{
    char proj[100];
    int sum;        
}ans;

typedef struct stud
{
    string stu;
    int pos;        
}stud;


ans p[101];
vector <stud> student(0);
char ss[100];
vector< set<string> > project(101);
bool cmp(ans a,ans b)
{
    if (a.sum>b.sum) return true;
    else if (a.sum==b.sum)
    {
        if (strcmp(a.proj,b.proj)==-1) return true;
        else return false;     
    }     
    else return false;
}


main()
{
   // freopen("A.1.dat","r",stdin);
   // freopen("out.txt","w",stdout);
    int index=0;
    int counter=0;
    int i,j;
    for(;;)
    {
        gets(ss);      
        if (ss[0]=='0') break;
        else if (ss[0]=='1') 
        {
           //  printf("index=%d\n",index);
             sort(p,p+index,cmp);
        for (i=0;i<index;i++)
        {
            printf("%s %d\n",p[i].proj,p[i].sum);    
        }     
      
             index=0;
             counter=0;
             student.clear();
             continue;
             
        }
        else
        {
        if (ss[0]>='A' && ss[0]<='Z')
        {
            strcpy(p[index].proj,ss);                                  
            i=index;
            index++;
            project[i].clear();
            p[i].sum=0;
            counter=0;
            
        }
        else
        {
            string sname="";
            for (j=0;j<strlen(ss);j++)
                sname+=ss[j];
            counter=project[i].size();
            project[i].insert(sname);
            if (project[i].size()-1==counter)
            {
                int tag=0;
                for (j=0;j<student.size();j++)
                {
                    if (sname==student[j].stu)
                    {
                        project[i].erase(sname);   
                        tag=1;
                        if (student[j].pos>=0)
                        {
                            project[student[j].pos].erase(sname);
                            p[student[j].pos].sum--;
                            student[j].pos=-1;
                        }
                        break;                   
                    }        
                }
                if (tag==0)
                {
                    stud tmp;
                    tmp.stu=sname;
                    tmp.pos=i;
                    student.push_back(tmp);           
                }
                p[i].sum=project[i].size();
               // printf("************************\n");
               // printf("%s %d\n",p[i].proj,p[i].sum);printf("************************\n");
            }
            else
            {
                continue;    
            }
        }
        
    }
    }
    
    
          
}

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh
Contact:

Re: 11239 - Open Source

Post by Shafaet_du » Sat Sep 25, 2010 12:42 pm

STL map should solve the problem.

Code: Select all

ROBOTS
me
and
noone
LINUX
isthebest
isthebest
noone
ELECTRONIX PROJECT
hateit
burned
hateit
hateit
noone
C PROJECT
iscool
iamhere
hellworld
linux
gui
iscool
me
THIS IS THE LAST
helloworld
thisisme
hopeyougetaccepted
1
0
output:

Code: Select all

C PROJECT 5
THIS IS THE LAST 3
ELECTRONIX PROJECT 2
LINUX 1
ROBOTS 1

Happy programming!!!

AbdAllah Boda
New poster
Posts: 6
Joined: Sat Dec 01, 2012 2:52 pm

Re: 11239 - Open Source

Post by AbdAllah Boda » Fri Nov 22, 2013 3:30 pm

i'm passing all cases i've seen here, and of course the simple input cases ...
but still getting WA :@ :@ ..
any help?

Code: Select all

// WA :(, no idea why? :(
//now it's AC :D
Last edited by AbdAllah Boda on Fri Nov 29, 2013 6:31 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11239 - Open Source

Post by brianfry713 » Sat Nov 23, 2013 12:47 am

Try input:

Code: Select all

AB
AA
1
0
Check input and AC output for thousands of problems on uDebug!

AbdAllah Boda
New poster
Posts: 6
Joined: Sat Dec 01, 2012 2:52 pm

Re: 11239 - Open Source

Post by AbdAllah Boda » Fri Nov 29, 2013 6:32 am

@ brianfry713
it's AC Now, thanx :D

Post Reply

Return to “Volume 112 (11200-11299)”