Page 1 of 1

765 WA!

Posted: Sat Nov 01, 2003 8:52 am
by boatfish
Any tricky testcases in this problem?
I think I have though about everything about it.
[cpp]#include<iostream>
#include<string>
#include<algorithm>
#include<memory.h>
using namespace std;

struct src{
int no;
string ref;
};

src ref[1000];
int ref_no[1000];
string reg[40000];
int ref_count=0,reg_count=0,current=0,buffer;

bool new_less(src a,src b){
return a.no<b.no;
}

string int_to_string(int n){
string result,no="0123456789";
while(n>0){
result=no[n%10]+result;
n/=10;
}
return result;
}

void print(){
int i;
for(i=0;i<ref_count;i++)
ref.no=ref_no[ref.no];
sort(ref,ref+ref_count,new_less);

for(i=1;i<=reg_count;i++)
cout<<reg<<endl;

for(i=0;i<ref_count;i++)
cout<<'['<<i+1<<']'<<ref.ref<<endl;
}

int main(){
memset(ref_no,-1,sizeof(ref_no));
string refe_no,temp;
bool space,content;
char bu;
while(cin.peek()!=EOF){
if(cin.peek()=='['){
cin>>refe_no;
refe_no=refe_no.substr(1,refe_no.length()-2);
ref[ref_count].no=atoi(refe_no.c_str());
while(cin.peek()!='\n' && cin.peek()!=EOF){
getline(cin,temp);
while(temp.length()>0 && temp[temp.length()-1]==' ')
temp=temp.substr(0,temp.length()-1);
if(temp=="")
break;
ref[ref_count].ref=ref[ref_count].ref+temp+'\n';
}
ref_count++;
}
else if(cin.peek()!='\n'){
reg_count++;
reg[reg_count]="";
content=false;
while(cin.peek()!='\n' && cin.peek()!=EOF){
space=true;
while(cin.peek()!='\n' && cin.peek()!=EOF){
cin.get(bu);
if(bu!=' ')
space=false;
reg[reg_count]=reg[reg_count]+bu;
if(bu=='['){
cin>>buffer;
if(ref_no[buffer]==-1){
current++;
ref_no[buffer]=current;
reg[reg_count]=reg[reg_count]+int_to_string(current);
}
else
reg[reg_count]=reg[reg_count]+int_to_string(ref_no[buffer]);
}
}
if(!space){
cin.get(bu);
reg[reg_count]=reg[reg_count]+bu;
content=true;
}
else if(!content)
reg_count--;
}
}
while(cin.peek()=='\n')
cin.get();
}

print();
return 0;
}[/cpp]

765 - References

Posted: Fri Mar 11, 2005 8:11 pm
by macan
It's a problem that you have to do what it says to do, but i'm always getting WA and I have tried all the sample inputs that are on ACM North-Eastern European Regional Contest page.
Now here are some questions I have:
Do we have to use files?
If it says up to 40000 lines do we have to implement it with a for (i=0;i<40000;i++) or with a while (gets()!=NULL)?
Do we have to read 1 line proced it anf print it, or do we have to process all lines and then print them?
Is there any tricky input?

Thanks in advanced

Posted: Fri Mar 11, 2005 8:34 pm
by ibrahim
Do we have to use files?
No you don't have to use file.
If it says up to 40000 lines do we have to implement it with a for (i=0;i<40000;i++) or with a while (gets()!=NULL)?
You don't have to use for loop. Just use EOF.


,
Ibrahim

Posted: Fri Mar 11, 2005 8:53 pm
by macan
Thanks Ibrahim,

char inputline[81];

so I'll use while(scanf("%s",inputline)!=EOF)){
execute code
}
right?. Another question I have is
If we don't have to use files, do we have to process a line and then print it and so on, or do we have to process all lines and them print them all in one time (all this excluding the reference description lines that will be printed all together at the end)?
the lines i have to declare are char inputline[81]; right?
The empty lines in the input will be lines with only blank spaces, right?
And finally, is there and empty line at the end?What about between the last regular paragraph and the reference description?

Thanks a lot!!

Posted: Fri Mar 11, 2005 9:32 pm
by ibrahim
macan wrote: char inputline[81];

so I'll use while(scanf("%s",inputline)!=EOF)){
execute code
}
right?.
I think here you can use " while(gets(input))) "
macan wrote: Another question I have is
If we don't have to use files, do we have to process a line and then print it and so on, or do we have to process all lines and them print them all in one time (all this excluding the reference description lines that will be printed all together at the end)?
I can't answere now, because i did not try it yet. I can say, if all the line are not dependent to each other, you don't need to process all the line at a time.

Posted: Sat Mar 12, 2005 2:20 pm
by macan
Ok, I have done everything that I have been told, but I still get WA and I can't make it on my own.
I thinks that it works correctly to any input and I don't know about the output.
I would really appreciate if any one can help me and run my code just to check if the way I do the output is correct.
It's not a lot of work, is just to help me out with something that it does not require programming knowledge but to know the correctly output way

Thanks in advanced

my code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct{
int nlin;
char linia[3][85];
int ordre;
}Format;

Format vecref[1000];
int ptext=1,pextra=1,pnum=1,ref=0,inici=1;
char numero[4];

void main(){
long int i,num;
int j,k,s,t,intro=1,blank=10;
char entrada[85],extra[85];

for (i=0;i<1000;i++){
vecref.ordre=0;
}


while(gets(entrada)){

t=0;
blank=1;
while (entrada[t]!='\0'){
if (entrada[t]!=' ') blank=0;
t++;
}
if (entrada[0]=='['&&intro==1||(ref==1&&blank==0)){
intro=0;
if (ref==0){
k=0;
j=1;
while(entrada[j]!=']'){
numero[j-1]=entrada[j];
j++;
}
numero[j]='\0';
num=atoi(numero);
j++;
s=0;
while(entrada[j]!='\0'){
vecref[num].linia[0][s]=entrada[j];
s++;
j++;
}
vecref[num].linia[0][s]='\0';
vecref[num].nlin=1;
ref=1;
k++;
}
else{
j=0;
while (entrada[j]!='\0'){
vecref[num].linia[k][j]=entrada[j];
j++;
}
vecref[num].linia[k][j]='\0';
k++;
vecref[num].nlin++;

}
}
else if((entrada[0]==' '&&blank==1)||entrada[0]=='\0'){
intro=1;
ref=0;
}
else{

ptext=0;
pextra=0;
if (intro==1&&inici==0){
printf("\n");
}
intro=0;
inici=0;
while(entrada[ptext]!='\0'){
if (entrada[ptext]=='['){
ptext++;
j=0;

while(entrada[ptext]!=']'){
numero[j]=entrada[ptext];
j++;
ptext++;
}
numero[j]='\0';
ptext++;
num=atoi(numero);
extra[pextra]='[';
if (vecref[num].ordre==0){
if (pnum<10){
pextra++;
extra[pextra]=pnum+48;
pextra++;
extra[pextra]=']';
}
else if (pnum<100){
pextra++;
extra[pextra+1]=pnum%10+48;
extra[pextra]=pnum/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=pnum/100+48;
extra[pextra+1]=(pnum/10)%10+48;
extra[pextra+2]=pnum%10+48;
pextra+=3;
extra[pextra]=']';
}
pextra++;
vecref[num].ordre=pnum;
pnum++;
}
else{

if (vecref[num].ordre<10){
pextra++;
extra[pextra]=vecref[num].ordre+48;
pextra++;
extra[pextra]=']';
}
else if (vecref[num].ordre<100){
pextra++;
extra[pextra+1]=(vecref[num].ordre)%10+48;
extra[pextra]=(vecref[num].ordre)/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=(vecref[num].ordre)/100+48;
extra[pextra+1]=((vecref[num].ordre)/10)%10+48;
extra[pextra+2]=(vecref[num].ordre)%10+48;
pextra+=3;
extra[pextra]=']';
}
pextra++;

}


}
extra[pextra]=entrada[ptext];
pextra++;
ptext++;

}
extra[pextra]='\0';
printf("%s\n",extra);
}
}
for (i=1;i<pnum;i++){
printf("\n");
pextra=0;
j=0;
while (vecref[j].ordre!=i) j++;
extra[pextra]='[';
if (vecref[j].ordre<10){
pextra++;
extra[pextra]=vecref[j].ordre+48;
pextra++;
extra[pextra]=']';
}
else if (vecref[j].ordre<100){
pextra++;
extra[pextra+1]=(vecref[j].ordre)%10+48;
extra[pextra]=(vecref[j].ordre)/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=(vecref[j].ordre)/100+48;
extra[pextra+1]=((vecref[j].ordre)/10)%10+48;
extra[pextra+2]=(vecref[j].ordre)%10+48;
pextra+=3;
extra[pextra]=']';
}
extra[pextra+1]='\0';
printf("%s%s\n",extra,vecref[j].linia[0]);
for (k=1;k<vecref[j].nlin;k++) printf("%s\n",vecref[j].linia[k]);

}

}

765 - We need help

Posted: Mon Mar 14, 2005 8:22 am
by macan
Ok, I have done everything that I have been told, but I still get WA and I can't make it on my own.
I think that it works correctly to any input but I'm not so sure about the output.
I would really appreciate if any one can help me and run my code just to check if the way I do the output is correct.
It's not work at all, it is just to help me out with something that it does not require programming knowledge but to know the correctly output way
I just need someone that already has done this problem and might know why I'm still getting WA. Then just run it and check what the problem might be.

Thanks in advanced

my code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct{
int nlin;
char linia[3][85];
int ordre;
}Format;

Format vecref[1000];
int ptext=1,pextra=1,pnum=1,ref=0,inici=1;
char numero[4];

void main(){
long int i,num;
int j,k,s,t,intro=1,blank=10;
char entrada[85],extra[85];

for (i=0;i<1000;i++){
vecref.ordre=-1;
}


while(gets(entrada)){

t=0;
blank=1;
while (entrada[t]!='\0'){
if (entrada[t]!=' ') blank=0;
t++;
}
if (entrada[0]=='['&&intro==1||(ref==1&&blank==0)){
intro=0;
if (ref==0){
k=0;
j=1;
while(entrada[j]!=']'){
numero[j-1]=entrada[j];
j++;
}
numero[j]='\0';
num=atoi(numero);
j++;
s=0;
while(entrada[j]!='\0'){
vecref[num].linia[0][s]=entrada[j];
s++;
j++;
}
vecref[num].linia[0][s]='\0';
vecref[num].nlin=1;
ref=1;
k++;
}
else{
j=0;
while (entrada[j]!='\0'){
vecref[num].linia[k][j]=entrada[j];
j++;
}
vecref[num].linia[k][j]='\0';
k++;
vecref[num].nlin++;

}
}
else if((entrada[0]==' '&&blank==1)||entrada[0]=='\0'){
intro=1;
ref=0;
}
else{

ptext=0;
pextra=0;
if (intro==1&&inici==0){
printf("\n");
}
intro=0;
inici=0;
while(entrada[ptext]!='\0'){
if (entrada[ptext]=='['){
ptext++;
j=0;

while(entrada[ptext]!=']'){
numero[j]=entrada[ptext];
j++;
ptext++;
}
numero[j]='\0';
ptext++;
num=atoi(numero);
extra[pextra]='[';
if (vecref[num].ordre==-1){
if (pnum<10){
pextra++;
extra[pextra]=pnum+48;
pextra++;
extra[pextra]=']';
}
else if (pnum<100){
pextra++;
extra[pextra+1]=pnum%10+48;
extra[pextra]=pnum/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=pnum/100+48;
extra[pextra+1]=(pnum/10)%10+48;
extra[pextra+2]=pnum%10+48;
pextra+=3;
extra[pextra]=']';
}
pextra++;
vecref[num].ordre=pnum;
pnum++;
}
else{

if (vecref[num].ordre<10){
pextra++;
extra[pextra]=vecref[num].ordre+48;
pextra++;
extra[pextra]=']';
}
else if (vecref[num].ordre<100){
pextra++;
extra[pextra+1]=(vecref[num].ordre)%10+48;
extra[pextra]=(vecref[num].ordre)/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=(vecref[num].ordre)/100+48;
extra[pextra+1]=((vecref[num].ordre)/10)%10+48;
extra[pextra+2]=(vecref[num].ordre)%10+48;
pextra+=3;
extra[pextra]=']';
}
pextra++;

}


}
extra[pextra]=entrada[ptext];
pextra++;
ptext++;

}
extra[pextra]='\0';
printf("%s\n",extra);
}
}
for (i=1;i<pnum;i++){
printf("\n");
pextra=0;
j=0;
while (vecref[j].ordre!=i) j++;
extra[pextra]='[';
if (vecref[j].ordre<10){
pextra++;
extra[pextra]=vecref[j].ordre+48;
pextra++;
extra[pextra]=']';
}
else if (vecref[j].ordre<100){
pextra++;
extra[pextra+1]=(vecref[j].ordre)%10+48;
extra[pextra]=(vecref[j].ordre)/10+48;
pextra+=2;
extra[pextra]=']';
}
else{
pextra++;
extra[pextra]=(vecref[j].ordre)/100+48;
extra[pextra+1]=((vecref[j].ordre)/10)%10+48;
extra[pextra+2]=(vecref[j].ordre)%10+48;
pextra+=3;
extra[pextra]=']';
}
extra[pextra+1]='\0';
printf("%s%s\n",extra,vecref[j].linia[0]);
for (k=1;k<vecref[j].nlin;k++) printf("%s\n",vecref[j].linia[k]);

}

}

Re: 765 - References

Posted: Thu Jul 24, 2008 11:24 pm
by x140l31
I'm always getting WA T.T

please can anyone help me? :(

Code: Select all

#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

typedef vector<string> VS;
typedef map<int, VS> MIS;
typedef MIS::iterator MIt;

int readInt(string s, int &i)
{
    int n = 0;
    while (s[i] != ']')
    {
        n = n*10 + (s[i] - '0');
        i++;
    }
    return n;
}

int reference(vector<int> &v, int ind)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] == ind) return i + 1;
    }
    v.push_back(ind);
    return v.size();
}

int main()
{
    string line;
    VS text;
    MIS ref;
    vector<int> v;
    while (getline(cin, line))
    {
        if (line.size() > 0 and line[0] == '[')
        {
            int i = 1;
            int ind = readInt(line, i);
            ref[ind].push_back(line.substr(i + 1));
            while (getline(cin, line) and line.size() > 0)
                ref[ind].push_back(line);
        }
        else text.push_back(line);
    }

    int lim = text.size() - 1;
    while (text[lim] == "") lim--;
    int i = 0;
    while (text[i] == "") i++;
    while (i <= lim)
    {
        for (int j = 0; j < text[i].size(); j++)
        {
            if (text[i][j] == '[')
            {
                j++;
                int ind = readInt(text[i], j);
                cout << '[' << reference(v, ind) << ']';
            }
            else cout << text[i][j];
        }
        cout << endl;
        if (text[i] == "")
            while (text[i] == "") i++;
        else i++;
    }

    for (i = 0; i < v.size(); i++)
    {
        cout << endl << '[' << i + 1 << ']';
        for (int j = 0; j < ref[v[i]].size(); j++) cout << ref[v[i]][j] << endl;
    }
}