11541 - Decoding
Moderator: Board moderators
11541 - Decoding
Every inputted string will be valid. That is, every letter will be followed by 1 or more digits.
You may assume the decoded string won’t have a length greater than 200 and it will only consist of upper case alphabets.
Does it mean that it may have a test case with one alphabet and a number with 199 digits??
That's incredibly lage....
Can anyone who has got accepted tell me how many digits you assume for the test case??
Thanks very much.
You may assume the decoded string won’t have a length greater than 200 and it will only consist of upper case alphabets.
Does it mean that it may have a test case with one alphabet and a number with 199 digits??
That's incredibly lage....
Can anyone who has got accepted tell me how many digits you assume for the test case??
Thanks very much.
Re: 11541 Decoding
It says the decoded string won't have a length greater than 200.
That means the output string is at most 200 characters long since the output string is actually the decoded string.
The input given is the encoded string.
A case like A205 will not be given since it's decoded string length would exceed 200.
Hope it helps.
That means the output string is at most 200 characters long since the output string is actually the decoded string.
The input given is the encoded string.
A case like A205 will not be given since it's decoded string length would exceed 200.
Hope it helps.
Re: 11541 - Decoding
very easy. u have declared 205 characters str. test case will not given 50. the input can be A-Z or 0-9 any characters.u cheeck ur problem input like
input
3 output
A0B0C1 C
A1B0C1D2 ACDD
the wrong format input will not given.
input
3 output
A0B0C1 C
A1B0C1D2 ACDD
the wrong format input will not given.
Re: 11541 - Decoding
hi
I hope sm could help me in this code
I don't know why it's WA
Thanks in advance
I hope sm could help me in this code
I don't know why it's WA
Code: Select all
#include<iostream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
using namespace std ;
string Repeted(char ch , int rep)
{
string result ;
for(int i=0 ; i<rep ; i++)
result+=ch ;
return result ;
}
int convert_to_int (string n)
{
int s=0 ;
for(int i=0 ;i<n.length();i++)
{
s+=(n[i]-'0');
if(i<n.length()-1)
s*=10;
}
return s ;
}
int main()
{
int cases ;
cin>>cases ;
for(int j=0 ; j<cases ; j++)
{
string inPut , outPut="" ,strNum;
int numRep=0 , size=0;
char ch;
cin>>inPut ;
for(int i=0 ; i<inPut.length() ; i++)
{
if(inPut[i]>='A'&&inPut[i]<='Z')
{
ch=inPut[i] ;
continue ;
}
while(inPut[i]>='1'&&inPut[i]<='9')
{
strNum+=inPut[i] ;
size++ ;
if((inPut[i+1]>='1'&&inPut[i+1]<='9'))
i++ ;
else break;
}
numRep = convert_to_int(strNum) ;
outPut+=Repeted(ch , numRep) ;
strNum="";
}
cout<<"Case "<<j+1<<":"<<outPut<<endl;
}
return 0 ;
}
-
- New poster
- Posts: 12
- Joined: Wed Aug 18, 2010 12:07 pm
Re: 11541 - Decoding WA Please help me
Code: Select all
#include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{
char a[2000];
int i,j,n[2000],t,k,count=0;
cin>>t;
for(k=1;k<=t;k++)
{count=0;
i=0;
scanf("%c",&a[i]);
cout<<"Case "<<k<<": ";
while(a[i]!='\n')
{
i++;
scanf("%d%c",&n[i-1],&a[i]);
if((int(a[i-1])>=65)&&(int(a[i-1])<=90))///////convetring upper case
{//a[i-1]=int (a[i-1])-32;
count=count+n[i-1];
// if(count==200)
// break;
//else
if(count>200)
n[i-1]=200+n[i-1]-count;
for(j=0;j<n[i-1];j++)
cout<<a[i-1];}
}
cout<<endl;
}
return 0;
}
uva=11541 i am gettign WA why.............
thank you very much brianfry i got AC after removing getchar()
Last edited by graph_dp on Sun Oct 07, 2012 11:58 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva=11541 i am gettign WA why.............
Doesn't match the sample I/O. Don't use a single getchar() and count on it being a newline, on some problems there may be different newline formats or trailing spaces.
Check input and AC output for thousands of problems on uDebug!
Re: 11541 - Decoding
Last edited by sith on Sun Dec 09, 2012 5:14 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11541 - Decoding
thank you,
silly typo
got AC
silly typo
got AC
Re: 11541 - Decoding
#include <stdio.h>
#include <string.h>
#define MAX 201
int main(){
static int T, t, i, j, k, K, f;
static char c,d, S[MAX], R[MAX];
freopen("in11541.txt", "r", stdin);
scanf("%d\n", &T);
for(t = 1; t <= T; t++){
scanf("%s", S);
for(i = 0, f = k = K = 0; (c = S) != '\0'; i++){
if(isalpha(c)){
if(f == 2){
for(j = 0; j < k; j++)
R[K++] = d;
k = 0;
}
f = 1;
d = c;
}else{
k = k*10+(c-48);
f = 2;
}
}
if(k > 0)
for(j = 0; j < k; j++)
R[K++] = d;
R[K] = '\0';
printf("Case %d: %s\n", t, R);
}
return 0;
}
I have faced WA. Please help
#include <string.h>
#define MAX 201
int main(){
static int T, t, i, j, k, K, f;
static char c,d, S[MAX], R[MAX];
freopen("in11541.txt", "r", stdin);
scanf("%d\n", &T);
for(t = 1; t <= T; t++){
scanf("%s", S);
for(i = 0, f = k = K = 0; (c = S) != '\0'; i++){
if(isalpha(c)){
if(f == 2){
for(j = 0; j < k; j++)
R[K++] = d;
k = 0;
}
f = 1;
d = c;
}else{
k = k*10+(c-48);
f = 2;
}
}
if(k > 0)
for(j = 0; j < k; j++)
R[K++] = d;
R[K] = '\0';
printf("Case %d: %s\n", t, R);
}
return 0;
}
I have faced WA. Please help
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11541 - Decoding
Don't read from a file
Check input and AC output for thousands of problems on uDebug!