Re: Why #444 WA?
Posted: Tue Jul 29, 2008 10:05 am
Seemed very easy problem to me but gave me RTE && i can't find any reason
.
Someone please help me.

Someone please help me.
Code: Select all
removed
Code: Select all
removed
Code: Select all
sprintf(b,"%lld",j);
Code: Select all
Removed after AC
Code: Select all
*abcd
Code: Select all
00199897923
Code: Select all
001
Code: Select all
d
Code: Select all
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main() {
int i, a, size;
string line, inv;
while (getline(cin, line)) {
size = line.size();
if(size==0)
{
cout<<endl;
continue;
}
if (line[0] < '0' || line[0] > '9') {
for (i = size - 1; i >= 0; i--) {
ostringstream osd;
osd << (int) line[i];
inv = osd.str();
reverse(inv.begin(), inv.end());
cout << inv;
}
} else {
for (i = size - 1; i >= 0; i--) {
ostringstream ose;
if (line[i] != '1') {
a = (line[i - 1] - 48)*10 + line[i] - 48;
i--;
} else {
a = (line[i - 2] - 48)*100 + (line[i - 1] - 48)*10 + line[i] - 48;
i = i - 2;
}
ose << a;
inv = ose.str();
reverse(inv.begin(), inv.end());
istringstream iss(inv);
iss >> a;
switch (a) {
case 7: cout << 'F';
break;
case 8: cout << 'P';
break;
case 9: cout << 'Z';
break;
case 1: cout << 'd';
break;
case 11: cout << 'o';
break;
case 12: cout << 'x';
break;
default: cout << (char) a;
break;
}
}
}
cout << endl;
}
return 0;
}
Just rewrite that part of code from scratch in a more natural way, without any hard-coded tables like that.Code: Select all
switch (a) { case 7: cout << 'F'; break; case 8: cout << 'P'; break; case 9: cout << 'Z'; break; case 1: cout << 'd'; break; case 11: cout << 'o'; break; case 12: cout << 'x'; break; default: cout << (char) a; break; }
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char msg[103];
while(gets(msg))
{
int len = strlen(msg)-1;
int temp=0;
while(len>=0)
{
if(msg[len]>='0' && msg[len]<='9')
{
temp = (int)msg[len] - '0';
if(len-1>=0)
{
temp = temp*10 + ((int)msg[len-1]-'0');
printf("%c",temp);
len-=2;
if(len==0)
{
temp = (int)msg[len]-'0';
printf("%c",temp);
len--;
}
}
else if(len==1)
{
temp = (int)msg[len--]-'0';
printf("%c",temp);
len--;
}
}
else
{
temp = msg[len];
while(temp!=0)
{
printf("%d",temp%10);
temp/=10;
}
len--;
}
}
printf("\n");
}
return 0;
}
this is given in problem statement.
You can assume a spy's message is at most 80 characters long, and it includes all the upper and lowercase letters of the alphabet plus the space, and any of the following characters:
! , . : ; ?
Code: Select all
aefd
z?.: ;e
001201
Code: Select all
00120110179
1019523856436221
fd