444 - Encoder and Decoder

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

Moderator: Board moderators

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

Re: 444 - Encoder and Decoder

Post by lighted »

Print a newline after each output line. You don't print newline after last output line
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 444 - Encoder and Decoder

Post by moudud99 »

changed in that code.JUST printed a new line But again WA
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 444 - Encoder and Decoder

Post by lighted »

I got accepted second time with your code. Remove printf after while and open commented printfs like this. Copy/paste from post above, not from your pc. :)

Code: Select all

while(gets(s))
{
    t++;
    int len=strlen(s);
    type=check(s);
    
    if(type==0)
    {
        ..
        printf("\n");
    }
    else
    {
        .. 
        printf("\n");
    }
}
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 444 - Encoder and Decoder

Post by moudud99 »

ah thanks I got AC :) :)
Nazim Gazi
New poster
Posts: 3
Joined: Wed Dec 10, 2014 11:23 am

Re: 444 - Encoder and Decoder

Post by Nazim Gazi »

Why I am getting WA. Please help...

Code: Select all

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0;i<(n);i++)
#define REP(i,a,b) for(__typeof(b) i=(a);i<=(b);i++)
#define INF (1<<31)
#define pb push_back
#define Sort(v) sort(v.begin(),v.end())
#define sz size()
#define mem(x,y) memset(x,y,sizeof(x))
#define sc scanf
#define pf printf
#define NL printf("\n")
#define mp make_pair
#define ff first
#define ss second
#define ri(N) scanf("%d",&N)
#define rs(S) scanf("%s",&S)
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >
#define vii vector<ii>
#define si set<int>
#define msi map<string,int>
#define fin freopen("input.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define pi acos(-1)
#define MAX 800
///////////////////////********************////////////////////////


/*Code start from here*/




int main()
{
    //fin;
    string s,ss;
    int len,asc;

    while(getline(cin,s))
    {
        ss.clear();
        len=s.sz;
        if(len==0)
        {
            NL;
            continue;
        }
        len--;
        if(s[0]>='0'&&s[0]<='9')
        {
          for(int i=0;i<=len;)
          {
              if(s[i+1]>='0'&&s[i+1]<='2')
                asc=(s[i+2]-'0')*100+(s[i+1]-'0')*10+s[i++]-'0';
              else
                asc=(s[i+1]-'0')*10+s[i]-'0';
                i+=2;
              ss+=char(asc);
          }
          for(int i=ss.sz-1;i>=0;i--)
            cout<<ss[i];
        }
        else
        {
            for(int i=len;i>=0;i--)
            {
                asc=int(s[i]);
                while(asc!=0)
                {
                    printf("%d",(asc%10));
                    asc/=10;
                }
            }
        }
        NL;

    }
    return 0;
}
metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 444 - Encoder and Decoder

Post by metaphysis »

The test data on uDebug contains:

Code: Select all

One is to write an encoder-decoder program here.
but the problem statement said that '-' is not a valid character, you should ignore input like this.
Post Reply

Return to “Volume 4 (400-499)”