865 - Substitution Cypher

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

Moderator: Board moderators

chetan
New poster
Posts: 43
Joined: Sun Sep 24, 2006 2:39 pm

Post by chetan » Sat Jul 14, 2007 8:41 am

why WA ???
please help

Code: Select all


CODE DELETED AFTER AC
            
Last edited by chetan on Sat Jul 14, 2007 6:04 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sat Jul 14, 2007 2:59 pm

I haven't found any error. Try submitting it again.
Ami ekhono shopno dekhi...
HomePage

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi » Sat Jul 14, 2007 5:25 pm

>>chetan

did u really got WA??
i submitted ur code without any making change and it got ACC!!

however, remove ur code from here.. :wink:

chetan
New poster
Posts: 43
Joined: Sun Sep 24, 2006 2:39 pm

Post by chetan » Sat Jul 14, 2007 6:05 pm

hmmmmmmmm............. may be i made a small change somewhere before submitting.
but anyways thanks a lot for your help
:D

RED-C0DE
New poster
Posts: 16
Joined: Mon Mar 26, 2007 6:47 pm

Post by RED-C0DE » Sun Aug 12, 2007 3:52 pm

i cant understand why can not get AC in this problem...

can anyone help me or give me some I/O

here is my C0DE :


Code: Select all


//uva#865	 Substitution Cypher
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cstdio>
//#include <fstream>

using namespace std;

int main()
{
//	ifstream cin("test.in");
	char ch;
	bool newLine = false;
	int T;
	
	cin >> T;
	cin .ignore(2);
	while(T--)
	{
		if(newLine)
			cout << endl;

		string plainText="" , substitution="";
		map <char,char> mapSubst;
		getline(cin , plainText);
		
		//filling the map :
		int szPlainText = plainText.size();
		size_t inxPlainText=0;
		while(szPlainText-- && cin >> ch )
		{
			mapSubst[ plainText[inxPlainText++] ] = ch;
			cout << ch;
		}
		cout << endl << plainText << endl;

		//*** :
		getline(cin , substitution);
		while(getline(cin , substitution) && substitution!= "")
		{
			size_t szSubs= substitution.size();
			for(size_t i=0; i<szSubs; i++)
			{
				if(mapSubst.find(substitution[i])!=mapSubst.end())
					cout << mapSubst[ substitution[i] ];
				else
					cout << substitution[i];
			}

			cout << endl;
		}

		newLine =true;
	}


	return 0;
}
tank u

saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

Re: 865 - Substitution Cypher

Post by saiful_sust » Thu May 28, 2009 10:11 pm

Hello RED-CODE
u programme give wa out put for
sedfcho input
try to read input from file && compare it with sedfcho output

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

865 - Substitution Cypher

Post by sazzadcsedu » Mon Jun 29, 2009 11:23 pm

nothing to display
Last edited by sazzadcsedu on Sat Jan 15, 2011 7:52 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

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

Re: 865 - Substitution Cypher

Post by Shafaet_du » Thu Dec 09, 2010 1:38 pm

If you are getting a wa, try the sample input posted in 1st page.

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

WA: 865 - Substitution Cypher (Faiem)

Post by faiem » Sun Apr 24, 2011 4:19 am

Why I m getting WA.

Code: Select all

#include<stdio.h>

int main()
{
/*
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
*/
    char cyper[26]={'z','y','x','w','v','u','t','s','r',
    'q','p','o','n','m','l','k','j','i','h','g','f','e','d','c',
    'b','a'};
    char ch;
    int test,T=1;
    scanf("%d",&test);
    getchar();
    getchar();
    while(test--)
    {
        if(T>1)
            printf("\n");
        while(1)
        {
            while((ch=getchar())!='\n')
            {
                if(ch>=97&&ch<=122)
                    printf("%c",cyper[ch-97]);
                else
                    printf("%c",ch);
                }
            printf("\n");
            ch=getchar();
            if(ch=='\n'||ch==EOF)
                break;
            else
                {
                    if(ch>=97&&ch<=122)
                        printf("%c",cyper[ch-97]);
                    else
                        printf("%c",ch);
                    }
            }
        T++;
        }
    return 0;
    }

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

Re: 865 - Substitution Cypher

Post by uDebug » Mon Mar 17, 2014 2:45 pm

Here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

2

abcdefghijklmnopqrstuvwxyz
mlpoknjiuhbvgytfcxdreszwaq
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Cras et mauris vestibulum, sodales erat et, dignissim urna. 
Donec ultrices dictum erat, id faucibus dui mollis auctor. 
Quisque convallis luctus nunc vitae gravida. Nullam quis orci 
eget ipsum ullamcorper consequat. Nam et bibendum elit. Proin 
sit amet congue odio. Nunc sodales vitae ligula non eleifend. 
Etiam iaculis ipsum at magna fermentum egestas. Proin quis 
felis vehicula, 

AeIoU
mPjHi
Tristique elit eget, feugiat nisi. Nullam tristique iaculis 
purus, sed laoreet sapien vestibulum vel. Quisque at 
consequat lectus. Sed posuere dignissim nulla, sit amet luctus 
ligula scelerisque non. Suspendisse eros ligula, 
ultricies in orci quis, tincidunt adipiscing neque. 
Aenean volutpat nec ipsum eget aliquam. Suspendisse potenti.
AC Output:

Code: Select all

mlpoknjiuhbvgytfcxdreszwaq
abcdefghijklmnopqrstuvwxyz
Ltxkg ufdeg otvtx dur mgkr, ptydkprkrex moufudpuyj kvur. 
Cxmd kr gmexud skdruleveg, dtomvkd kxmr kr, oujyuddug exym. 
Dtykp evrxupkd oupreg kxmr, uo nmepuled oeu gtvvud meprtx. 
Qeudcek ptysmvvud vepred yeyp surmk jxmsuom. Nevvmg ceud txpu 
kjkr ufdeg evvmgptxfkx ptydkcemr. Nmg kr lulkyoeg kvur. Pxtuy 
dur mgkr ptyjek tout. Neyp dtomvkd surmk vujevm yty kvkunkyo. 
Erumg umpevud ufdeg mr gmjym nkxgkyreg kjkdrmd. Pxtuy ceud 
nkvud skiupevm, 

mPjHi
AeIoU
TristiquP Plit PgPt, fPugiat nisi. Nullam tristiquP iaculis 
purus, sPd laHrPPt sapiPn vPstibulum vPl. QuisquP at 
cHnsPquat lPctus. SPd pHsuPrP dignissim nulla, sit amPt luctus 
ligula scPlPrisquP nHn. SuspPndissP PrHs ligula, 
ultriciPs in Hrci quis, tincidunt adipiscing nPquP. 
mPnPan vHlutpat nPc ipsum PgPt aliquam. SuspPndissP pHtPnti.
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: WA: 865 - Substitution Cypher (Faiem)

Post by uDebug » Mon Mar 17, 2014 2:49 pm

faiem wrote:Why I m getting WA.
Try running your code on the input I just now posted.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

Re: 865 - Substitution Cypher

Post by unreleased » Thu Feb 12, 2015 2:28 am

why WA??

Code: Select all

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <utility>
#include <bitset>

#define mx 1000000
#define INT 2147483647

#define D   double
#define L   long
#define LL  long long
#define ULL unsigned long long

#define isc1(a)      scanf("%d", &a)
#define isc2(a,b)    scanf("%d%d", &a, &b)
#define isc3(a,b,c)  scanf("%d%d%d", &a, &b, &c)
#define llsc1(a)     scanf("%I64d", &a)
#define llsc2(a,b)   scanf("%I64d%I64d", &a, &b)
#define llsc3(a,b,c) scanf("%I64d %I64d %I64d", &a,&b,&c)

#define f(a,n)  for(a=0; a<n; a++)
#define all(a)  a.begin(), a.end()
#define ms(arr) memset(arr, 0, sizeof(arr))
#define cl(a)   a.clear()
#define sz(a)   a.size()

#define sc scanf
#define pf printf
#define pu push_back
#define pb pop_back
#define vc vector
#define mp make_pair
#define fi first
#define se second
#define pip pf("pip.....\n")

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
    int a,b,c, d;

    string str,temp, from, to;
    int len, tst, arr[250];
    isc1(tst); getchar(); getchar(); c=0;
    while(tst--)
    {
        if(c)pf("\n\n");c=1;

        cin>>from>>to;  getchar();
        cout<<to<<"\n"<<from<<"\n";

        ms(arr);
        for(a=0; a<=sz(from); a++) arr[from[a]]=(int) to[a];

        d=0;
        while(getline(cin, str))
        {

            len=sz(str);
            if(len && d)pf("\n"); d=1;
            if(len==0) break;

            for(a=0; a<len; a++)
            {
                //if(str[a]=='\0'){pf("\n");continue;}

                if(arr[str[a]])pf("%c", arr[str[a]]);
                else pf("%c", str[a]);
            }


        }

    }

    return 0;
}

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

Re: 865 - Substitution Cypher

Post by brianfry713 » Thu Feb 12, 2015 10:37 pm

Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

Re: 865 - Substitution Cypher

Post by unreleased » Fri Feb 13, 2015 5:02 am

brianfry713 wrote:Always print a newline char at the end of the last line.
aah its WA too after adding a newline at the end :( ....

Code: Select all

        #include <iostream>
        #include <cstdio>
        #include <string>
        #include <cstring>
        #include <cmath>
        #include <vector>
        #include <stack>
        #include <queue>
        #include <algorithm>
        #include <iterator>
        #include <map>
        #include <set>
        #include <sstream>
        #include <utility>
        #include <bitset>

        #define mx 1000000
        #define INT 2147483647

        #define D   double
        #define L   long
        #define LL  long long
        #define ULL unsigned long long

        #define isc1(a)      scanf("%d", &a)
        #define isc2(a,b)    scanf("%d%d", &a, &b)
        #define isc3(a,b,c)  scanf("%d%d%d", &a, &b, &c)
        #define llsc1(a)     scanf("%I64d", &a)
        #define llsc2(a,b)   scanf("%I64d%I64d", &a, &b)
        #define llsc3(a,b,c) scanf("%I64d %I64d %I64d", &a,&b,&c)

        #define f(a,n)  for(a=0; a<n; a++)
        #define all(a)  a.begin(), a.end()
        #define ms(arr) memset(arr, 0, sizeof(arr))
        #define cl(a)   a.clear()
        #define sz(a)   a.size()

        #define sc scanf
        #define pf printf
        #define pu push_back
        #define pb pop_back
        #define vc vector
        #define mp make_pair
        #define fi first
        #define se second
        #define pip pf("pip.....\n")

        using namespace std;

        int main()
        {
            //freopen("input.txt", "r", stdin);
            int a,b,c, d;

            string str,temp, from, to;
            int len, tst, arr[250];
            isc1(tst); getchar(); getchar(); c=0;
            while(tst--)
            {
                //if(c)puts("");c=1;

                cin>>from>>to;  getchar();
                cout<<to<<"\n"<<from<<"\n";

                ms(arr);
                for(a=0; a<=sz(from); a++) arr[from[a]]=(int) to[a];

                d=0;
                while(getline(cin, str))
                {

                    len=sz(str);
                    //if(len && d)pf("\n"); d=1;
                    if(len==0) break;

                    for(a=0; a<len; a++)
                    {
                        //if(str[a]=='\0'){pf("\n");continue;}

                        if(arr[str[a]])pf("%c", arr[str[a]]);
                        else pf("%c", str[a]);
                    }
                    puts("");

                }
                puts("");

            }

            return 0;
        }

Post Reply

Return to “Volume 8 (800-899)”