11223 - O: dah dah dah!

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

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: 11223 - O: dah dah dah!

Post by kissu parina » Sat Jan 15, 2011 11:36 am

plz help....getting WA.

Code: Select all

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
#include<map>
int main(){
map<string,char>ma;
ma[".-"]='A';
ma["-..."]='B';
ma["-.-."]='C';
ma["-.."]='D';
ma["."]='E';
ma["..-."]='F';
ma["--."]='G';
ma["...."]='H';
ma[".."]='I';
ma[".---"]='J';
ma["-.-"]='K';
ma[".-.."]='L';
ma["--"]='M';
ma["-."]='N';
ma["---"]='O';
ma[".--."]='P';
ma["--.-"]='Q';
ma[".-."]='R';
ma["..."]='S';
ma["-"]='T';
ma["..-"]='U';
ma["...-"]='V';
ma[".--"]='W';
ma["-..-"]='X';
ma["-.--"]='Y';
ma["--.."]='Z';
ma[".----"]='1';
ma["..---"]='2';
ma["...--"]='3';
ma["....-"]='4';
ma["....."]='5';
ma["-...."]='6';
ma["--..."]='7';
ma["---.."]='8';
ma["----."]='9';
ma["-----"]='0';
ma[".-.-.-"]='.';
ma["---..."]=':';
ma["--..--"]=',';
ma["-.-.-."]=';';
ma["..--.."]='?';
ma["-...-"]='=';
ma[".----."]='\'';
ma[".-.-."]='+';
ma["-.-.--"]='!';
ma["-....-"]='-';
ma["-..-."]='/';
ma["..--.-"]='_';
ma["-.--."]='(';
ma[".-..-."]='"';
ma["-.--.-"]=')';
ma[".--.-."]='@';
ma[".-..."]='&';
	char str[2030],ss[2005];
	string axe;
	int tst,kase=1;
	scanf("%d",&tst);
              getchar();
	int r=tst;
	while(tst--){
		gets(str);
		printf("Message #%d\n",kase++);
		char *t=str;
		int p=0;
		while(*t){
			if(*t==' '&&*(t+1)==' '){printf(" ");t++;}
			else if(*t==' '&&*(t+1)!=' ');
			else {
				ss[p++]=*t;
				if(*(t+1)==' '||*(t+1)==NULL){
					ss[p]='\0';
					axe=ss;
					p=0;
					cout<<ma[axe];	
				}
			}
			t++;
		}
		ss[p]='\0';
		axe=ss;
		p=0;
		cout<<ma[axe];
		printf("\n");
		if(kase-1!=r)printf("\n");
	}
	return 0;
}
one day...

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 11223 - O: dah dah dah!

Post by sazzadcsedu » Sat Jan 15, 2011 5:03 pm

..
Last edited by sazzadcsedu on Mon Jan 17, 2011 1:28 pm, edited 1 time in total.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: 11223 - O: dah dah dah!

Post by kissu parina » Sun Jan 16, 2011 1:33 pm

thnkx for ur reply bt i dont think those assignments were wrong..... :D
anymore suggestions will be appreciated
one day...

SeineRiver
New poster
Posts: 2
Joined: Mon Jan 24, 2011 8:00 am

Re: 11223 - O: dah dah dah!

Post by SeineRiver » Mon Jan 24, 2011 8:08 am

I found most solution posts above (with test cases) are quite misleading. So there're something to clarify:

There's no such thing like "ssss" in test cases. There are at most 2 consecutive spaces, and there's no trailing / leading space either.

If you get WA (i got for 3 times :P), don't bother to change your code to handle cases mentioned above. Be rest assure that 95% the problem is in your mapping array, there must be something wrong there. In such case, this test should be useful (copied from a PG's post)
Input:
3
.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ...- ..- ...- .-- -..- -.-- --..
.---- ..--- ...-- ....- ..... -.... --... ---.. ----. -----
.-.-.- .----. -.--. ---... .-.-. .-..-. -....- -.-.-- -.--.- -.-.-. -....- .--.-. ..--.. -..-. .-... -...- ..--.-
Output:
Message #1
ABCDEFGHIJKLMNOPQRVUVWXYZ

Message #2
1234567890

Message #3
.'(:+"-!);-@?/&=_

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: 11223 - O: dah dah dah!

Post by kissu parina » Sat Feb 05, 2011 4:33 pm

thnkx...i have solved it :D
one day...

shohan008
New poster
Posts: 1
Joined: Thu Apr 07, 2011 6:13 pm

Re: 11223 - O: dah dah dah!

Post by shohan008 » Thu Apr 07, 2011 6:19 pm

I got 12 WA. And wast 2 days to AC it. But always WA. Plz plz help me...

Code: Select all

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
	char line[3050];
	char tmp[100],c;
	int t1,test,i,l,index;
	while(scanf("%d",&test)!=EOF)
{
	scanf("%c",&c);
	for(t1=1;t1<=test;t1++)
	{
		gets(line);
		l=strlen(line);
		cout<<"Message "<<t1<<endl;
		index=0;
		for(i=0;i<l;i++)
		{
			if(line[i] != ' ')
			{
				tmp[index] = line[i];
				index++;
			}
			if(line[i] == ' ' || i==l-1)
			{
				tmp[index]=0;
				if(strcmp(tmp,".-" ) == 0)
					cout << "A";
				else if(strcmp(tmp,"-..." ) == 0)
					cout << "B";
				else if(strcmp(tmp,"-.-." ) == 0)
					cout << "C";
				else if(strcmp(tmp,"-.." ) == 0)
					cout << "D";
				else if(strcmp(tmp,"." ) == 0)
					cout << "E";
				else if(strcmp(tmp,"..-." ) == 0)
					cout << "F";
				else if(strcmp(tmp,"--." ) == 0)
					cout << "G";
				else if(strcmp(tmp,"...." ) == 0)
					cout << "H";
				else if(strcmp(tmp,".." ) == 0)
					cout << "I";
				else if(strcmp(tmp,".---" ) == 0)
					cout << "J";
				else if(strcmp(tmp,"-.-" ) == 0)
					cout << "K";
				else if(strcmp(tmp,".-.." ) == 0)
					cout << "L";
				else if(strcmp(tmp,"--" ) == 0)
					cout << "M";
				else if(strcmp(tmp,"-." ) == 0)
					cout << "N";
				else if(strcmp(tmp,"---" ) == 0)
					cout << "O";
				else if(strcmp(tmp,".--." ) == 0)
					cout << "P";
				else if(strcmp(tmp,"--.-" ) == 0)
					cout << "Q";
				else if(strcmp(tmp,".-." ) == 0)
					cout << "R";
				else if(strcmp(tmp,"..." ) == 0)
					cout << "S";
				else if(strcmp(tmp,"-" ) == 0)
					cout << "T";
				else if(strcmp(tmp,"..-" ) == 0)
					cout << "U";
				else if(strcmp(tmp,"...-" ) == 0)
					cout << "V";
				else if(strcmp(tmp,".--" ) == 0)
					cout << "W";
				else if(strcmp(tmp,"-..-" ) == 0)
					cout << "X";
				else if(strcmp(tmp,"-.--" ) == 0)
					cout << "Y";
				else if(strcmp(tmp,"--.." ) == 0)
					cout << "Z";
				else if(strcmp(tmp,"-----" ) == 0)
					cout << "0";
				else if(strcmp(tmp,".----." ) == 0)
					cout << "1";
				else if(strcmp(tmp,"..---" ) == 0)
					cout << "2";
				else if(strcmp(tmp,"...--" ) == 0)
					cout << "3";
				else if(strcmp(tmp,"....-" ) == 0)
					cout << "4";
				else if(strcmp(tmp,"....." ) == 0)
					cout << "5";
				else if(strcmp(tmp,"-...." ) == 0)
					cout << "6";
				else if(strcmp(tmp,"--..." ) == 0)
					cout << "7";
				else if(strcmp(tmp,"---.." ) == 0)
					cout << "8";
				else if(strcmp(tmp,"----." ) == 0)
					cout << "9";
				else if(strcmp(tmp,".-.-.-" ) == 0)
					cout << ".";
				else if(strcmp(tmp,"--..--" ) == 0)
					cout << ",";
				else if(strcmp(tmp,"..--.." ) == 0)
					cout << "?";
				else if(strcmp(tmp,".----." ) == 0)
					cout << "'";
				else if(strcmp(tmp,"-.-.--" ) == 0)
					cout << "!";
				else if(strcmp(tmp,"-..-." ) == 0)
					cout << "/";
				else if(strcmp(tmp,"-.--." ) == 0)
					cout << "(";
				else if(strcmp(tmp,"-.--.-" ) == 0)
					cout << ")";
				else if(strcmp(tmp,".-..." ) == 0)
					cout << "&";
				else if(strcmp(tmp,"---..." ) == 0)
					cout << ":";
				else if(strcmp(tmp,"-.-.-." ) == 0)
					cout << ";";
				else if(strcmp(tmp,"-...-" ) == 0)
					cout << "=";
				else if(strcmp(tmp,".-.-." ) == 0)
					cout << "+";
				else if(strcmp(tmp,"-....-" ) == 0)
					cout << "-";
				else if(strcmp(tmp,"..--.-" ) == 0)
					cout << "_";
				else if(strcmp(tmp,".-..-." ) == 0)
					cout << char(34);
				else if(strcmp(tmp,".--.-." ) == 0)
					cout << "@";
				if(line[i+1] ==' ')
				{
					cout << " ";
					i++;
				};
				index=0;
			}
		}
		cout<<"\n";
		if(t1!=test)
			cout<<"\n";
	}
}

return 0;
}


surya ss
New poster
Posts: 22
Joined: Sat Jun 11, 2005 7:31 pm

Re: 11223 - O: dah dah dah!

Post by surya ss » Thu May 19, 2011 6:45 pm

for concern about input in this problem:
there's trailing space in the end of the line for the test case
my code got PE when assuming there's not

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 11223 - O: dah dah dah!

Post by live_lie » Wed Jun 15, 2011 6:11 pm

my code give the same output for the given input , but still wrong answer.
thank you "SeineRiver" for the input set

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 11223 - O: dah dah dah!

Post by live_lie » Wed Jun 15, 2011 6:32 pm

please someone tell me whats the problem with my code......WA...??

Code: Select all

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
    int i,j;
    map<string,char> listOfSymbol;


    listOfSymbol [".-"]='A';
	listOfSymbol [".---"]='J';
    listOfSymbol ["..."]='S';
    listOfSymbol [".----"]='1';
    listOfSymbol [".-.-.-"]='.';
    listOfSymbol ["---..."]=':';
    listOfSymbol ["-..."]='B';
	listOfSymbol ["-.-"]='K';
	listOfSymbol ["-"]='T';
	listOfSymbol ["..---"]='2';
	listOfSymbol ["--..--"]=',';
	listOfSymbol ["-.-.-."]=';';
    listOfSymbol ["-.-."]='C';
    listOfSymbol    [".-.."]='L';
    listOfSymbol	["..-"]='U';
    listOfSymbol	["...--"]='3';
    listOfSymbol    ["..--.."]='?';
    listOfSymbol	["-...-"]='=';
    listOfSymbol	["-.."]='D';
    listOfSymbol    ["--"]='M';
    listOfSymbol	["...-"]='V';
    listOfSymbol	["....-"]='4';
    listOfSymbol	[".----."]='\'';
    listOfSymbol	[".-.-."]='+';
    listOfSymbol	["."]='E';
    listOfSymbol	["-."]='N';
    listOfSymbol	[".--"]='W';
    listOfSymbol	["....."]='5';
    listOfSymbol	["-.-.--"]='!';
    listOfSymbol	["-....-"]='-';
    listOfSymbol	["..-."]='F';
    listOfSymbol	["---"]='O';
    listOfSymbol	["-..-"]='X';
    listOfSymbol	["-...."]='6';
    listOfSymbol	["-..-."]='/';
    listOfSymbol	["..--.-"]='_';
    listOfSymbol 	["--."]='G';
    listOfSymbol	[".--."]='P';
    listOfSymbol	["-.--"]='Y';
    listOfSymbol	["--..."]='7';
    listOfSymbol	["-.--."]='(';
    listOfSymbol 	[".-..-."]='"';
    listOfSymbol 	["...."]='H';
    listOfSymbol	["--.-"]='Q';
    listOfSymbol	["--.."]='Z';
    listOfSymbol 	["---.."]='8';
    listOfSymbol 	["-.--.-"]=')';
    listOfSymbol	[".--.-."]='@';
    listOfSymbol	[".."]='I';
    listOfSymbol	[".-."]='R';
    listOfSymbol	["-----"]='0';
    listOfSymbol 	["----."]='9';
    listOfSymbol 	[".-..."]='&';

    int testCase,t;
    string temps;
    string message;
    cin>>testCase;
    cin.ignore();
    bool space;
    char temp;
    for(t=0;t<testCase;t++)
    {
        getline(cin,message);
        if(t!=0)
        cout<<endl;

        cout<<"Message #"<<t+1<<endl;
        i=0;
        space=false;
        temps.clear();
        while(i<message.size())
        {
            temp=message[i];
            if(isspace(temp))
            {
                if(!space)
                {
                    cout<<listOfSymbol[temps];
                    space=true;
                    temps.clear();
                }
                else
                {
                    cout<<" ";
                    space=false;
                }
            }
            else
            {
                temps.push_back(temp);
                space=false;
            }

            i++;
        }
        cout<<listOfSymbol[temps]<<endl;
    }


    return 0;
}

please help.

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 11223 - O: dah dah dah!

Post by live_lie » Wed Jun 15, 2011 6:34 pm

my code give the right output for all the test cases given by all of you...but why wrong aswer..?

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11223 - O: dah dah dah!

Post by uDebug » Fri Mar 07, 2014 8:30 am

On the first page, ignore the input / output provided by sapnil and Jan. It just confused me. Every AC program I tried printed a different output for that input. The judge's data's pretty straightforward and there are no "gotchas". If you look around the thread for the more thorough posts (like SeineRiver indicates), you should be fine.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11223 - O: dah dah dah!

Post by uDebug » Fri Mar 07, 2014 8:33 am

live_lie wrote:my code give the right output for all the test cases given by all of you...but why wrong aswer..?
What you posted is AC code.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

dosthim
New poster
Posts: 1
Joined: Thu Dec 25, 2014 7:17 pm

Re: 11223 - O: dah dah dah!

Post by dosthim » Thu Dec 25, 2014 7:22 pm

Please somebody help me. i got wrong answer and then now presentation error. whats wrong in my code?

Code: Select all


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

class Main{

	/**
	 * @param args
	 */
	private static Map<String,Character> mSymbolMap = new HashMap<String,Character>();
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		initializeMap();
		String line = null;String[] tmp = null;
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		line = reader.readLine();
		int noOfTestCase = Integer.parseInt(line);
		boolean newLine = true;
		for(int i=0;i<noOfTestCase;i++){
			line="";
			tmp=reader.readLine().split("  ");
			if(tmp!=null)
				for(int j=0;j<tmp.length;j++){
					String[] tmp2 = tmp[j].split(" ");
					for(int k=0;k<tmp2.length;k++){
						if(mSymbolMap.containsKey(tmp2[k])){
							line = line+mSymbolMap.get(tmp2[k]);
						}
					}
					
					line +=" "; 
				}
			
			System.out.println("Message #"+(i+1));
			System.out.println(line);
			if(i==noOfTestCase-1)
				newLine=false;
			if(newLine){
			System.out.println();
			}
			
		}
		
	}

	private static void initializeMap() {
		
		/**
		 * Map 
		 * 
Symbol	Code	Symbol	Code	Symbol	Code	Symbol	Code	Symbol	Code	Symbol	Code
A	.-	J	.- - -	S	...	1	.- - - -	.	.-.-.-	:	- - -...
B	-...	K	-.-	T	-	2	..- - -	,	- -..- -	;	-.-.-.
C	-.-.	L	.-..	U	..-	3	...- -	?	..--..	=	-...-
D	-..	M	- -	V	...-	4	....-	'	.- - - -.	+	.-.-.
E	.	N	-.	W	.- -	5	.....	!	-.-.- -	-	-....-
F	..-.	O	- - -	X	-..-	6	-....	/	-..-.	_	..- -.-
G	- -.	P	.- -.	Y	-.- -	7	- -...	(	-.- -.	"	.-..-.
H	....	Q	- -.-	Z	- -..	8	- - -..	)	-.- -.-	@	.- -.-.
I	..	R	.-.	0	- - - - -	9	- - - -.	&	.-...	
		 */
		mSymbolMap.put(".-", 'A');mSymbolMap.put("-...", 'B');mSymbolMap.put("-.-.", 'C');
		mSymbolMap.put("-..", 'D');mSymbolMap.put(".", 'E');mSymbolMap.put("..-.", 'F');
        mSymbolMap.put("--.", 'G');mSymbolMap.put("....", 'H');mSymbolMap.put("..", 'I');
		mSymbolMap.put(".---", 'J');mSymbolMap.put("-.-", 'K');mSymbolMap.put(".-..", 'L');
		mSymbolMap.put("--", 'M');mSymbolMap.put("-.", 'N');mSymbolMap.put("---", 'O');
		mSymbolMap.put(".--.", 'P');mSymbolMap.put("--.-", 'Q');mSymbolMap.put(".-.", 'R');
		mSymbolMap.put("...", 'S');mSymbolMap.put("-", 'T');mSymbolMap.put("..-", 'U');
		mSymbolMap.put("...-", 'V');mSymbolMap.put(".--", 'W');mSymbolMap.put("-..-", 'X');
		mSymbolMap.put("-.--", 'Y');mSymbolMap.put("--..", 'Z');mSymbolMap.put("-----", '0');
		mSymbolMap.put(".----", '1');mSymbolMap.put("..---", '2');mSymbolMap.put("...--", '3');
		mSymbolMap.put("....-", '4');mSymbolMap.put(".....", '5');mSymbolMap.put("-....", '6');
		mSymbolMap.put("--...", '7');mSymbolMap.put("---..", '8');mSymbolMap.put("----.", '9');
		mSymbolMap.put(".-.-.-", '.');mSymbolMap.put("--..--", ',');mSymbolMap.put("..--..", '?');
		mSymbolMap.put(".----.", "'".charAt(0));mSymbolMap.put("-.-.--", '!');mSymbolMap.put("-..-.", '/');
		mSymbolMap.put("-.--.", '(');mSymbolMap.put("-.--.-", ')');mSymbolMap.put(".-...", '&');
		mSymbolMap.put("---...", ':');mSymbolMap.put("-.-.-.", ';');mSymbolMap.put("-...-", '=');
		mSymbolMap.put(".-.-.", '+');mSymbolMap.put("-....-", '-');mSymbolMap.put("..--.-", '_');
		mSymbolMap.put(".-..-.", '"');mSymbolMap.put(".--.-.", '@');
	}

}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11223 - O: dah dah dah!

Post by lighted » Fri Dec 26, 2014 12:40 pm

Don't print extra space at the end of each line.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 112 (11200-11299)”