Page 1 of 2
11239 - Open Source
Posted: Sun Jul 15, 2007 3:38 am
by SHAHADAT
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
-----------------------------------------------------------------
LIFE IS COMBINED WITH JOY AND SORROW.IT IS NOT ONLY FOR SITTING IN A ROOM AND TYPING CODE.
Posted: Sun Jul 15, 2007 4:11 am
by mmonish
Try this case
input
output
Hope this helps.
asd
Posted: Sun Jul 15, 2007 7:25 am
by darkos32
i've also got WA..can anyone give me testcases ?
thanks...
Posted: Sun Jul 15, 2007 7:47 am
by Rocky
to darkos32:
Do u try mmonish test case..????
try with some more:
input
output
oh..yes there is no information about the length of the project name and student name....check it.
GOOD LUCK
Rocky
asd
Posted: Sun Jul 15, 2007 7:57 am
by darkos32
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..
Posted: Sun Jul 15, 2007 10:11 am
by rushel
I think use of STL will simplify things
Posted: Sun Jul 15, 2007 10:48 am
by SHAHADAT
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.
Posted: Sun Jul 15, 2007 10:11 pm
by hamedv
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;
}
}
Posted: Tue Jul 17, 2007 5:22 am
by David Kjaer
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...
Posted: Sun Jul 22, 2007 4:33 pm
by hamedv
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

Posted: Thu Jul 26, 2007 7:32 pm
by zhj5825
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;
}
}
}
}
}
Re: 11239 - Open Source
Posted: Sat Sep 25, 2010 12:42 pm
by Shafaet_du
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!!!
Re: 11239 - Open Source
Posted: Fri Nov 22, 2013 3:30 pm
by AbdAllah Boda
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
Re: 11239 - Open Source
Posted: Sat Nov 23, 2013 12:47 am
by brianfry713
Re: 11239 - Open Source
Posted: Fri Nov 29, 2013 6:32 am
by AbdAllah Boda
@ brianfry713
it's AC Now, thanx
