Page 2 of 3

159 WA, cant understand why? help me plz!

Posted: Sun Oct 09, 2005 12:52 am
by zerg
Here is my code:

Code: Select all

import java.io.*;
import java.util.*;


class Main {

    static String ReadLn(int maxLg)
    {
        byte lin[] = new byte [maxLg];
        int lg = 0, car = -1;
        String line = "";

        try {
            while (lg < maxLg) {
                car = System.in.read();
                if ((car < 0) || (car == '\n')) break;
                lin[lg++] += car;
            }
        }
        catch (IOException e) {
            return (null);
        }

        if ((car < 0) && (lg == 0)) return (null);
        return (new String(lin, 0, lg));
    }

    public static void main(String args[])
    {
        Main myWork = new Main();
        try {
            myWork.start();
        } catch (Throwable throwable) {
            System.out.println("Unable to make two crosses");
        }
    }

    void start() throws Throwable{
        String input;
        StringTokenizer t;
        String word1, word2, word3, word4;

        while ((input = Main.ReadLn (255)) != null) {
            if(input.equals("#")) break;
            t = new StringTokenizer(input);
            word1 = t.nextToken();
            word2 = t.nextToken();
            word3 = t.nextToken();
            word4 = t.nextToken();
            formCrosses(word1, word2, word3, word4);
        }
    }

    void formCrosses(String word1, String word2, String word3, String word4) throws RuntimeException{
        int word1Length, word2Length, word3Length, word4Length, width, height;
        int[] pair1CrossIndexes, pair2CrossIndexes;
        char[][] matrix;

        word1Length = word1.length();
        word2Length = word2.length();
        word3Length = word3.length();
        word4Length = word4.length();
        if(word1Length>10 || word2Length>10 || word3Length>10 || word4Length>10)
            throw new RuntimeException();
        pair1CrossIndexes = getCrossIndexes(word1, word2);
        pair2CrossIndexes = getCrossIndexes(word3, word4);
        if (pair1CrossIndexes != null && pair2CrossIndexes != null) {
            width = word1Length + word2Length + 3;
            int h_words_y = Math.max(pair1CrossIndexes[1], pair2CrossIndexes[1]);
            height = h_words_y  + Math.max(word2Length - pair1CrossIndexes[1], word4Length - pair2CrossIndexes[1]);
            matrix = new char[height][width];
            fillWithSpaces(matrix);
            int i=0;
            for (i = 0; i < word1.length(); i++)
                 matrix[h_words_y][i]=word1.charAt(i);
            for (i = 0; i < word3.length(); i++)
                 matrix[h_words_y][i+word1Length+3]=word3.charAt(i);
            for (i = 0; i < word2.length(); i++)
                 matrix[h_words_y-pair1CrossIndexes[1]+i][pair1CrossIndexes[0]]=word2.charAt(i);
            for (i = 0; i < word4.length(); i++)
                 matrix[h_words_y-pair2CrossIndexes[1]+i][pair2CrossIndexes[0]+word1Length+3]=word4.charAt(i);
            printMatrix(matrix);
        } else
            System.out.println("Unable to make two crosses");
        System.out.println();
    }

    void printMatrix(char[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            char[] chars = matrix[i];
            System.out.println(chars);
        }
    }

    void fillWithSpaces(char[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            char[] chars = matrix[i];
            for (int j = 0; j < chars.length; j++) {
                chars[j]=' ';
            }
        }
    }

    int[] getCrossIndexes(String word1, String word2) {
        int[] result = null;
        for (int word1CrossIndex = 0; word1CrossIndex < word1.length(); word1CrossIndex++) {
            char word1Char = word1.charAt(word1CrossIndex);
            int word2CrossIndex = word2.indexOf(word1Char);
            if (word2CrossIndex != -1) {
                result = new int[2];
                result[0] = word1CrossIndex;
                result[1] = word2CrossIndex;
                break;
            }
        }
        return result;
    }
}
Could anyone tell me whats wrong with my code? Or maybe show me test case when my code doesn't work properly.

Posted: Sun Oct 09, 2005 1:34 am
by zerg
WA problem is solved :lol:
width = word1Length + word2Length + 3; - here was error
width = word1Length + word3Length + 3; - corrected
And now i have presentation error :evil:

159 WA plz help me.

Posted: Fri Mar 10, 2006 9:57 am
by dspeyuri
this is my code and i cant find what the problem is
plz help me

Code: Select all

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

int main (){
	
	char str[100];
	char seps[6]=" \t\0\n";
	char *t,*cross;
	char word[1000][20];
	char temp[2][20];
	int cnt_i[2],cnt_j[2];
	int i,j,k,maxword,n,len;
	int s_len[4];
	char board[30][30];

	k=0;	
	for(i=0;i<1000;i++)
		memcpy(word[i]," ",20);
	
	while(1){
		gets(str);
		t = strtok(str,seps);
		if(strcmp(t,"#")==0) break;
		strcpy(word[k],t);
		for(i=k+1;i<=k+3;i++){
			t = strtok(NULL,seps);
			strcpy(word[i],t);
		}
		k+=4;
	}
	maxword=k;		
	k=0;
	
	while(1){		
		for(i=0;i<30;i++)
			for(j=0;j<30;j++)
				board[i][j]=' '; 
		
		if(k>=maxword) break;
		
		memcpy(temp[0]," ",20);
		memcpy(temp[1]," ",20);

		cnt_i[0]=-1;
		cnt_i[1]=-1;
		cnt_j[0]=-1;
		cnt_j[1]=-1;

		s_len[0]=strlen(word[k]);
		s_len[1]=strlen(word[k+1]);
		s_len[2]=strlen(word[k+2]);
		s_len[3]=strlen(word[k+3]);

		strcpy(temp[0],word[k]);
		strcpy(temp[1],word[k+2]);

		t=strcat(temp[0],"   ");
		cross=strcat(t,temp[1]);

		for(i=0;i<s_len[0];i++){
			for(j=0;j<s_len[1];j++){
				if(word[k][i]==word[k+1][j]){
					cnt_i[0]=i;
					cnt_j[0]=j;
					break;
				}
			}
			if(cnt_i[0]!=-1) break;
		}
		for(i=0;i<s_len[2];i++){
			for(j=0;j<s_len[3];j++){
				if(word[k+2][i]==word[k+3][j]){
					cnt_i[1]=i;
					cnt_j[1]=j;
					break;
				}
			}
			if(cnt_i[1]!=-1) break;
		}
	
		if(cnt_i[0]<0 || cnt_i[1]<0){
			printf("Unable to make two crosses\n");
		}	
		else{
			n=cnt_j[0]-cnt_j[1];	
			
			if(n>0){
				if(s_len[1] < s_len[3]+n) len=s_len[3]+n;
				else len=s_len[1];
		
				for(i=0;i<n;i++)
					board[i][cnt_i[0]]=word[k+1][i];
				for(j=i;j<len;j++){
					board[j][cnt_i[0]]=word[k+1][j];
					board[j][strlen(word[k])+cnt_i[1]+3]=word[k+3][j-i];
				}
				strcpy(board[cnt_j[0]],cross);
			}
			if(n<0){
				if(s_len[1]-n < s_len[3]) len=s_len[3];
				else len=len=s_len[1]-n;
		
				for(i=0;i<-n;i++)
					board[i][s_len[0]+3+cnt_i[1]]=word[k+3][i];
				for(j=i;j<len;j++){
					board[j][cnt_i[0]]=word[k+1][j-i];
					board[j][s_len[0]+cnt_i[1]+3]=word[k+3][j];
				}
				strcpy(board[cnt_j[1]],cross);
			}
			if(n==0){
				if(s_len[1] < s_len[3]) len=s_len[3];
				else len=s_len[1];
						
				for(j=0;j<len;j++){
					board[j][cnt_i[0]]=word[k+1][j];
					board[j][strlen(word[k])+cnt_i[1]+3]=word[k+3][j];
				}
				strcpy(board[cnt_j[0]],cross);
			}			
			for(i=0;i<len;i++){
				for(j=0;j<30;j++)
					printf("%c",board[i][j]);
					printf("\n");
			}		
		}		
		printf("\n");
		k+=4;
	}
}
i have tested many times and always right. :evil:

Posted: Mon Apr 16, 2007 8:13 am
by algoJo
Hi I've always got PE in this problem, can someone tell me what's wrong?
INPUT:

Code: Select all

MATCHES CHEESECAKE PICNIC EXCUSES
EXCUSES PICNIC MATCHES CHEESECAKE
EXCUSES PICNIC CHEESECAKE MATCHEX
PEANUT BANANA VACUUM  GREEDY
BALL CATAM BALL BA
CATAM BALL BA BALL
CATAM BALL BALL BA
CHEESECAKE MATCHES PICNIC EXCUSESSS
LIDYA WATI ASEP SURASEP
SURASEP ASEP WATI LIDYA
ASEP WATI LIDYA SURASEP
WATI ASEP SURASEP LIDYA
JAPANESE AMERICAN VIETNAMNESE CHINESE
CHINESE JAPANESE AMERICAN VIETNAMNESE
UNIVERSITAS BINA NUSANTARA JAKARTA
UNIVERSITAS BINA JAKARTA NUSANTARA
BINA NUSANTARA UNIVERSITAS JAKARTA
BINA NUSANTARA JAKARTA UNIVERSITAS
BINA JAKARTA NUSANTARA UNIVERSITAS
JAKARTA BINA NUSANTARA UNIVERSITAS
JAKARTA BINA UNIVERSITAS NUSANTARA
JAKARTA UNIVERSITAS NUSANTARA BINA
JAKARTA UNIVERSITAS BINA NUSANTARA
A A B B
STRINGA STRINGB STRINGC STRINGD
ASEP BOSS KUMA LAMA
ASEP BOSS LAMA KUMA
BOSS ASEP KUMA LAMA
BOSS ASEP LAMA KUMA
BOSS LAMA ASEP KUMA
BOSS LAMAM KUMA ASEP
#
OUTPUT:

Code: Select all

_C
_H
_E
_E
_S
_E__________E
_C__________X
MATCHES   PICNIC
_K__________U
_E__________S
____________E
____________S

___________C
___________H
___________E
___________E
___________S
__P________E
__I________C
EXCUSES   MATCHES
__N________K
__I________E
__C

__________M
__P_______A
__I_______T
EXCUSES   CHEESECAKE
__N_______H
__I_______E
__C_______X

Unable to make two crosses

_C
BALL   BALL
_T_____A
_A
_M

_B
CATAM   BA
_L______A
_L______L
________L

_B
CATAM   BALL
_L______A
_L

M
A______________E
T______________X
CHEESECAKE   PICNIC
H______________U
E______________S
S______________E
_______________S
_______________S
_______________S

_W______S
_A______U
_T______R
LIDYA   ASEP
________S
________E
________P

___________L
___________I
___________D
A__________Y
SURASEP   WATI
E
P

___________S
___________U
W__________R
ASEP   LIDYA
T__________S
I__________E
___________P

__________L
__________I
__________D
__________Y
WATI   SURASEP
_S
_E
_P

____________C
____________H
JAPANESE   VIETNAMNESE
_M__________N
_E__________E
_R__________S
_I__________E
_C
_A
_N

__________V
___J______I
___A______E
___P______T
___A______N
CHINESE   AMERICAN
___E______M
___S______N
___E______E
__________S
__________E

_B
_I_______________J
UNIVERSITAS   NUSANTARA
_A_______________K
_________________A
_________________R
_________________T
_________________A

_______________N
_B_____________U
_I_____________S
UNIVERSITAS   JAKARTA
_A_____________N
_______________T
_______________A
_______________R
_______________A

____________J
____________A
____________K
____________A
BINA   UNIVERSITAS
__U_________T
__S_________A
__A
__N
__T
__A
__R
__A

________U
________N
________I
________V
________E
________R
________S
________I
________T
BINA   JAKARTA
__U_____S
__S
__A
__N
__T
__A
__R
__A

___J___U
BINA   NUSANTARA
___K___I
___A___V
___R___E
___T___R
___A___S
_______I
_______T
_______A
_______S

_B
_I
_N________U
JAKARTA   NUSANTARA
__________I
__________V
__________E
__________R
__________S
__________I
__________T
__________A
__________S

_B
_I
_N________N
JAKARTA   UNIVERSITAS
__________S
__________A
__________N
__________T
__________A
__________R
__________A

_U
_N
_I
_V
_E
_R
_S
_I________B
_T________I
JAKARTA   NUSANTARA
_S________A

_U
_N
_I
_V
_E
_R
_S
_I
_T
JAKARTA   BINA
_S__________U
____________S
____________A
____________N
____________T
____________A
____________R
____________A

A   B

STRINGA   STRINGC
T_________T
R_________R
I_________I
N_________N
G_________G
B_________D

_B_______L
_O_______A
ASEP   KUMA
_S_______A

________K
_B______U
_O______M
ASEP   LAMA
_S

_________L
__A______A
BOSS   KUMA
__E______A
__P

________K
________U
__A_____M
BOSS   LAMA
__E
__P

Unable to make two crosses

Unable to make two crosses


note: '_' means a space
Thanks for your help... :D

Posted: Mon Apr 16, 2007 3:46 pm
by Jan
My accepted code returns same output. But I can't fully understand your output though. The problem states
Leave 1 blank line between output sets.
Did you consider this?

159 - Word Crosses-Wrong answer

Posted: Wed Aug 21, 2013 10:58 am
by dennisorz
Please help me find bug!

Code: Select all

#include <iostream>
#include <string.h>
using namespace std;
int posh[2],posw[2],F=0;                         //cross size
void str(char a[],char b[],int num);                    //compare string
void Fprint(char h1[],char v1[],char h2[],char v2[]);  //print
int main(){
    int i,j,f;
    int frist=0;
    char h1[20],v1[20],h2[20],v2[20];      //word
                     
   
    while(true){
		cin >> h1 >> v1 >> h2 >> v2;                      //input
		if(frist)
		   cout <<endl;
		F=0;
		if(h1[0] == '#')
		   break;
		else{
			  str(h1,v1,0);
			  
		      if(F==1){
					F=0;
					str(h2,v2,1);
					if(F==1)
					   Fprint(h1,v1,h2,v2);
					else
					    cout<<"Unable to make two crosses"<<endl;   
			  }
		            //cout<<posh[0]<<','<<posw[0]<<','<<posh[1]<<','<<posw[1]<<endl;
		       else
		            cout<<"Unable to make two crosses"<<endl;
		}
		
    } 
    return 0;
}
void str(char h[],char v[],int num){
	int i,j;
	string a=h,b=v;
	for(i=0;i<a.length();i++){
		        for(j=0;j<b.length();j++){
					if(h[i] == v[j]){
						posh[num]=j;
						posw[num]=i;
						F=1;
						break;
					}
					
			    }
			    if(F==1)
			        break;
			    
	}
	
	
}
void Fprint(char h1[],char v1[],char h2[],char v2[]){
	char print[50][50];  
	int i,j,L,W;
	string a=h1,b=v1,c=h2,d=v2;
	//initial
    for(j=0;j<50;j++){
		for(i=0;i<50;i++){
			      print[i][j]='f';
			      
		}
    }
	  
    
    //fristpair is high
	if(posh[0]>=posh[1]){
		//fristpair-fristword
		for(i=0;i<a.length();i++)
		    print[i][posh[0]]=h1[i];
		//fristpair-secondword
		for(j=0;j<b.length();j++)
			print[posw[0]][j]=v1[j];
		//secondpair-fristword
		for(i=0;i<c.length();i++)
		    print[i+a.length()+3][posh[0]]=h2[i];
		//secondpair-secondword
		for(j=0;j<d.length();j++)
			print[a.length()+3+posw[1]][j+posh[0]-posh[1]]=v2[j];	
		//set length,width
		W=a.length()+c.length()+3;
		if(posh[0]-posh[1]+d.length()>=b.length()){
			    L=posh[0]-posh[1]+d.length();
				//print result
		        for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[0]&&j<posh[0]-posh[1])
					        break;
						else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
						    break;
						else if(i>a.length()+3+posw[1]&&j>posh[0])
						    break;
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
	    }		
		else{
				L=b.length();
			    //print result
			    for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[0]&&j<posh[0]-posh[1])
					        break;
						else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
						    break;
						else if(i>a.length()+3+posw[1]&&j>posh[0])
						    break;
						else if(i>posw[0]&&j>posh[0]-posh[1]+c.length())
						    break;    
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
	    }  
	    
		
	}
	//secondpair is high
	else{
		//fristpair-fristword
		for(i=0;i<a.length();i++)
		    print[i][posh[1]]=h1[i];
		//fristpair-secondword
		for(j=0;j<b.length();j++)
			print[posw[0]][j+(posh[1]-posh[0])]=v1[j];
		//secondpair-fristword
		for(i=0;i<c.length();i++)
		    print[i+a.length()+3][posh[1]]=h2[i];
		//secondpair-secondword
		for(j=0;j<d.length();j++)
			print[a.length()+3+posw[1]][j]=v2[j];	
		//set length,width
		W=a.length()+c.length()+3;	
		if(posh[1]-posh[0]+b.length()>=d.length()){
			L=posh[1]-posh[0]+b.length();
			for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[1]+a.length()+3&&j<posh[1])
					        break;
						else if(i>posw[1]+a.length()+3&&j>posh[1]) 
						    break;
						else if(i>posw[0]&&j>d.length())
						    break;
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
				
	    } 
		else{
		    L=d.length();
			for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[1]+a.length()+3&&j<posh[1])
					        break;
						else if(i>posw[1]+a.length()+3&&j>posh[1]) 
						    break;
						else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }	
	
	    }
	}
	
}

Re: 159 - Word Crosses-Wrong answer

Posted: Wed Aug 21, 2013 9:27 pm
by brianfry713
Leave 1 blank line between output sets.

Re: 159 - Word Crosses-Wrong answer

Posted: Thu Aug 22, 2013 3:47 pm
by dennisorz
sorry!worng answer!

Code: Select all

#include <iostream>
#include <string.h>
using namespace std;
int posh[2],posw[2],F=0;                         //cross size
void str(char a[],char b[],int num);                    //compare string
void Fprint(char h1[],char v1[],char h2[],char v2[]);  //print
int main(){
    int i,j,f;
    int frist=0;
    char h1[20],v1[20],h2[20],v2[20];      //word
                     
   
    while(true){
		cin >> h1 >> v1 >> h2 >> v2;                      //input
		F=0;
		if(h1[0] == '#')
		   break;
		else{
			  str(h1,v1,0);
			  
		      if(F==1){
					F=0;
					str(h2,v2,1);
					if(F==1)
					   Fprint(h1,v1,h2,v2);
					else
					    cout<<"Unable to make two crosses"<<endl;   
			  }
		            //cout<<posh[0]<<','<<posw[0]<<','<<posh[1]<<','<<posw[1]<<endl;
		       else
		            cout<<"Unable to make two crosses"<<endl;
		}
		cout<<endl;
		
    } 
    return 0;
}
void str(char h[],char v[],int num){
	int i,j;
	string a=h,b=v;
	for(i=0;i<a.length();i++){
		        for(j=0;j<b.length();j++){
					if(h[i] == v[j]){
						posh[num]=j;
						posw[num]=i;
						F=1;
						break;
					}
					
			    }
			    if(F==1)
			        break;
			    
	}
	
	
}
void Fprint(char h1[],char v1[],char h2[],char v2[]){
	char print[50][50];  
	int i,j,L,W;
	string a=h1,b=v1,c=h2,d=v2;
	//initial
    for(j=0;j<50;j++){
		for(i=0;i<50;i++){
			      print[i][j]='f';
			      
		}
    }
	  
    
    //fristpair is high
	if(posh[0]>=posh[1]){
		//fristpair-fristword
		for(i=0;i<a.length();i++)
		    print[i][posh[0]]=h1[i];
		//fristpair-secondword
		for(j=0;j<b.length();j++)
			print[posw[0]][j]=v1[j];
		//secondpair-fristword
		for(i=0;i<c.length();i++)
		    print[i+a.length()+3][posh[0]]=h2[i];
		//secondpair-secondword
		for(j=0;j<d.length();j++)
			print[a.length()+3+posw[1]][j+posh[0]-posh[1]]=v2[j];	
		//set length,width
		W=a.length()+c.length()+3;
		if(posh[0]-posh[1]+d.length()>=b.length()){
			    L=posh[0]-posh[1]+d.length();
				//print result
		        for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[0]&&j<posh[0]-posh[1])
					        break;
						else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
						    break;
						else if(i>a.length()+3+posw[1]&&j>posh[0])
						    break;
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
	    }		
		else{
				L=b.length();
			    //print result
			    for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[0]&&j<posh[0]-posh[1])
					        break;
						else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
						    break;
						else if(i>a.length()+3+posw[1]&&j>posh[0])
						    break;
						else if(i>posw[0]&&j>posh[0]-posh[1]+c.length())
						    break;    
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
	    }  
	    
		
	}
	//secondpair is high
	else{
		//fristpair-fristword
		for(i=0;i<a.length();i++)
		    print[i][posh[1]]=h1[i];
		//fristpair-secondword
		for(j=0;j<b.length();j++)
			print[posw[0]][j+(posh[1]-posh[0])]=v1[j];
		//secondpair-fristword
		for(i=0;i<c.length();i++)
		    print[i+a.length()+3][posh[1]]=h2[i];
		//secondpair-secondword
		for(j=0;j<d.length();j++)
			print[a.length()+3+posw[1]][j]=v2[j];	
		//set length,width
		W=a.length()+c.length()+3;	
		if(posh[1]-posh[0]+b.length()>=d.length()){
			L=posh[1]-posh[0]+b.length();
			for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[1]+a.length()+3&&j<posh[1])
					        break;
						else if(i>posw[1]+a.length()+3&&j>posh[1]) 
						    break;
						else if(i>posw[0]&&j>d.length())
						    break;
					    else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }
				
	    } 
		else{
		    L=d.length();
			for(j=0;j<L;j++){
				   for(i=0;i<W;i++){
					    if(print[i][j]!='f')
					        cout<<print[i][j];
					    else if(i>posw[1]+a.length()+3&&j<posh[1])
					        break;
						else if(i>posw[1]+a.length()+3&&j>posh[1]) 
						    break;
						else
					        cout<<' ';       
				   } 
				   cout <<endl;
		        }	
	
	    }
	}
	
}

Re: 159 - Word Crosses-Wrong answer

Posted: Thu Aug 22, 2013 11:50 pm
by brianfry713
Leave 1 blank line between output sets. Don't print an extra blank line at the end of the output.

Re: 159 - Word Crosses-Wrong answer

Posted: Fri Aug 23, 2013 8:34 am
by dennisorz
Oh no~~?wrong answer!

Code: Select all

#include <iostream>
#include <string.h>
using namespace std;
int posh[2],posw[2],F=0;                         //cross size
void str(char a[],char b[],int num);                    //compare string
void Fprint(char h1[],char v1[],char h2[],char v2[]);  //print
int main(){
    int i,j,f;
    int frist=0;
    char h1[20],v1[20],h2[20],v2[20];      //word
                     
   
    while(true){
      cin >> h1 >> v1 >> h2 >> v2;                      //input
      if(frist)
         cout <<endl;
      frist=1;
      F=0;
      if(h1[0] == '#')
         break;
      else{
           str(h1,v1,0);
           
            if(F==1){
               F=0;
               str(h2,v2,1);
               if(F==1)
                  Fprint(h1,v1,h2,v2);
               else
                   cout<<"Unable to make two crosses"<<endl;   
           }
                  //cout<<posh[0]<<','<<posw[0]<<','<<posh[1]<<','<<posw[1]<<endl;
             else
                  cout<<"Unable to make two crosses"<<endl;
      }
      
    } 
    return 0;
}
void str(char h[],char v[],int num){
   int i,j;
   string a=h,b=v;
   for(i=0;i<a.length();i++){
              for(j=0;j<b.length();j++){
               if(h[i] == v[j]){
                  posh[num]=j;
                  posw[num]=i;
                  F=1;
                  break;
               }
               
             }
             if(F==1)
                 break;
             
   }
   
   
}
void Fprint(char h1[],char v1[],char h2[],char v2[]){
   char print[50][50];  
   int i,j,L,W;
   string a=h1,b=v1,c=h2,d=v2;
   //initial
    for(j=0;j<50;j++){
      for(i=0;i<50;i++){
               print[i][j]='f';
               
      }
    }
     
    
    //fristpair is high
   if(posh[0]>=posh[1]){
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[0]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[0]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j+posh[0]-posh[1]]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;
      if(posh[0]-posh[1]+d.length()>=b.length()){
             L=posh[0]-posh[1]+d.length();
            //print result
              for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }      
      else{
            L=b.length();
             //print result
             for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                  else if(i>posw[0]&&j>posh[0]-posh[1]+c.length())
                      break;    
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }  
       
      
   }
   //secondpair is high
   else{
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[1]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j+(posh[1]-posh[0])]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[1]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;   
      if(posh[1]-posh[0]+b.length()>=d.length()){
         L=posh[1]-posh[0]+b.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else if(i>posw[0]&&j>d.length())
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
            
       } 
      else{
          L=d.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else
                       cout<<' ';       
               } 
               cout <<endl;
              }   
   
       }
   }
   
}

Re: 159 - Word Crosses-Wrong answer

Posted: Sat Aug 24, 2013 12:56 am
by brianfry713
brianfry713 wrote:Leave 1 blank line between output sets. Don't print an extra blank line at the end of the output.

Re: 159 - Word Crosses-Wrong answer

Posted: Sun Aug 25, 2013 7:02 am
by dennisorz

Code: Select all

#include <iostream>
#include <string.h>
using namespace std;
int posh[2],posw[2],F=0;                         //cross size
void str(char a[],char b[],int num);                    //compare string
void Fprint(char h1[],char v1[],char h2[],char v2[]);  //print
int main(){
    int i,j,f;
    int frist=0;
    char h1[20],v1[20],h2[20],v2[20];      //word
                     
   
    while(true){
      cin >> h1 >> v1 >> h2 >> v2;                      //input
      //if(frist)
      //   cout <<endl;
      //frist=1;
      F=0;
      if(h1[0] == '#')
         break;
      else{
           str(h1,v1,0);
           
            if(F==1){
               F=0;
               str(h2,v2,1);
               if(F==1)
                  Fprint(h1,v1,h2,v2);
               else
                   cout<<"Unable to make two crosses"<<endl;   
           }
                  //cout<<posh[0]<<','<<posw[0]<<','<<posh[1]<<','<<posw[1]<<endl;
             else
                  cout<<"Unable to make two crosses"<<endl;
      }
      
    } 
    return 0;
}
void str(char h[],char v[],int num){
   int i,j;
   string a=h,b=v;
   for(i=0;i<a.length();i++){
              for(j=0;j<b.length();j++){
               if(h[i] == v[j]){
                  posh[num]=j;
                  posw[num]=i;
                  F=1;
                  break;
               }
               
             }
             if(F==1)
                 break;
             
   }
   
   
}
void Fprint(char h1[],char v1[],char h2[],char v2[]){
   char print[50][50];  
   int i,j,L,W;
   string a=h1,b=v1,c=h2,d=v2;
   //initial
    for(j=0;j<50;j++){
      for(i=0;i<50;i++){
               print[i][j]='f';
               
      }
    }
     
    
    //fristpair is high
   if(posh[0]>=posh[1]){
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[0]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[0]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j+posh[0]-posh[1]]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;
      if(posh[0]-posh[1]+d.length()>=b.length()){
             L=posh[0]-posh[1]+d.length();
            //print result
              for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }      
      else{
            L=b.length();
             //print result
             for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                  else if(i>posw[0]&&j>posh[0]-posh[1]+c.length())
                      break;    
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }  
       
      
   }
   //secondpair is high
   else{
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[1]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j+(posh[1]-posh[0])]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[1]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;   
      if(posh[1]-posh[0]+b.length()>=d.length()){
         L=posh[1]-posh[0]+b.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else if(i>posw[0]&&j>d.length())
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
            
       } 
      else{
          L=d.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else
                       cout<<' ';       
               } 
               cout <<endl;
              }   
   
       }
   }
   cout<<endl;
}

Re: 159 - Word Crosses-Wrong answer

Posted: Tue Aug 27, 2013 12:30 am
by brianfry713
Don't print spaces at the end of a line.

159 Way? WA

Posted: Thu Sep 05, 2013 12:01 pm
by dennisorz

Code: Select all

#include <iostream>
#include <string.h>
using namespace std;
int posh[2],posw[2],F=0;                         //cross size
void str(char a[],char b[],int num);                    //compare string
void Fprint(char h1[],char v1[],char h2[],char v2[]);  //print
int main(){
    int i,j,f;
    int frist=0;
    char h1[20],v1[20],h2[20],v2[20];      //word
                     
   
    while(true){
      cin >> h1 >> v1 >> h2 >> v2;                      //input
      if(frist)
         cout <<endl;
      frist=1;
      F=0;
      if(h1[0] == '#')
         break;
      else{
           str(h1,v1,0);
           
            if(F==1){
               F=0;
               str(h2,v2,1);
               if(F==1)
                  Fprint(h1,v1,h2,v2);
               else
                   cout<<"Unable to make two crosses"<<endl;   
           }
                  //cout<<posh[0]<<','<<posw[0]<<','<<posh[1]<<','<<posw[1]<<endl;
             else
                  cout<<"Unable to make two crosses"<<endl;
      }
      
    } 
    return 0;
}
void str(char h[],char v[],int num){
   int i,j;
   string a=h,b=v;
   for(i=0;i<a.length();i++){
              for(j=0;j<b.length();j++){
               if(h[i] == v[j]){
                  posh[num]=j;
                  posw[num]=i;
                  F=1;
                  break;
               }
               
             }
             if(F==1)
                 break;
             
   }
   
   
}
void Fprint(char h1[],char v1[],char h2[],char v2[]){
   char print[50][50];  
   int i,j,L,W;
   string a=h1,b=v1,c=h2,d=v2;
   //initial
    for(j=0;j<50;j++){
      for(i=0;i<50;i++){
               print[i][j]='f';
               
      }
    }
     
    
    //fristpair is high
   if(posh[0]>=posh[1]){
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[0]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[0]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j+posh[0]-posh[1]]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;
      if(posh[0]-posh[1]+d.length()>=b.length()){
             L=posh[0]-posh[1]+d.length();
            //print result
              for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }      
      else{
            L=b.length();
             //print result
             for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[0]&&j<posh[0]-posh[1])
                       break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0]-posh[1]&&j<posh[0]) 
                      break;
                  else if(i>a.length()+3+posw[1]&&j>posh[0])
                      break;
                  else if(i>posw[0]&&j>posh[0]-posh[1]+c.length())
                      break;    
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
       }  
       
      
   }
   //secondpair is high
   else{
      //fristpair-fristword
      for(i=0;i<a.length();i++)
          print[i][posh[1]]=h1[i];
      //fristpair-secondword
      for(j=0;j<b.length();j++)
         print[posw[0]][j+(posh[1]-posh[0])]=v1[j];
      //secondpair-fristword
      for(i=0;i<c.length();i++)
          print[i+a.length()+3][posh[1]]=h2[i];
      //secondpair-secondword
      for(j=0;j<d.length();j++)
         print[a.length()+3+posw[1]][j]=v2[j];   
      //set length,width
      W=a.length()+c.length()+3;   
      if(posh[1]-posh[0]+b.length()>=d.length()){
         L=posh[1]-posh[0]+b.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else if(i>posw[0]&&j>d.length())
                      break;
                   else
                       cout<<' ';       
               } 
               cout <<endl;
              }
            
       } 
      else{
          L=d.length();
         for(j=0;j<L;j++){
               for(i=0;i<W;i++){
                   if(print[i][j]!='f')
                       cout<<print[i][j];
                   else if(i>posw[1]+a.length()+3&&j<posh[1])
                       break;
                  else if(i>posw[1]+a.length()+3&&j>posh[1]) 
                      break;
                  else
                       cout<<' ';       
               } 
               cout <<endl;
              }   
   
       }
   }
   //cout<<endl;
}

Re: 159 Way? WA

Posted: Thu Sep 05, 2013 9:36 pm
by brianfry713
Don't print spaces at the end of a line.
Leave 1 blank line between output sets. Don't print an extra blank line at the end of the output.