uva 10101

The forum to report every bug you find or tell us what you'd like to find in UVa OJ

Moderator: Board moderators

Post Reply
Yusuf_sust
New poster
Posts: 2
Joined: Wed Dec 16, 2015 3:03 am

uva 10101

Post by Yusuf_sust » Wed Dec 16, 2015 3:06 am

Why get WA.
Here is my code

#include <stdio.h>
#include <string.h>

int main()
{
int i, j, k, l, t = 1;
char s[100], s1[200];
while(gets(s))
{
l = strlen(s);
j = 0;
for(i = l - 1; i >= 0;)
{
if(s != '0' || s[i-1] != '0')
{
s1[j++] = s[i--];
}
else
i--;
if(i >= 0)
{
if(s != '0')
s1[j++] = s[i--];
else
i--;
}
if(i >= 0)
{
if(s != '0')
{
if(s[i + 1] != '0' || s[i + 2] != '0')
s1[j++] = ' ';
s1[j++]= 'a', s1[j++]= 't', s1[j++]= 'a', s1[j++] = 'h', s1[j++]= 's', s1[j++]= ' ';
s1[j++] = s[i--];
}
else
i--;
}
if(i >= 0)
{
if(s != '0' || s[i-1] != '0')
{
s1[j++]= ' ',s1[j++]= 'r', s1[j++]= 'a', s1[j++]= 'j', s1[j++] = 'a', s1[j++]= 'h', s1[j++]= ' ';
s1[j++] = s[i--];
}
else
i--;
}
if(i >= 0)
{
if(s != '0')
s1[j++] = s[i--];
else
i--;
}
if(i >= 0)
{
if(s != '0' || s[i-1] != '0')
{
s1[j++]= ' ',s1[j++]= 'h', s1[j++]= 'k', s1[j++]= 'a', s1[j++] = 'l', s1[j++]= ' ';
s1[j++] = s[i--];
}
else
i--;
}
if(i >= 0)
{
if(s != '0')
s1[j++] = s[i--];
else
i--;
}

if(i >= 0)
{
s1[j++]= ' ',s1[j++]= 'i', s1[j++]= 't', s1[j++]= 'u', s1[j++] = 'k', s1[j++] = ' ';
}
}
if(t >= 1000)
printf("%d. ", t++);
else if(t >= 100)
printf(" %d. ", t++);
else if(t >= 10)
printf(" %d. ", t++);
else
printf(" %d. ", t++);
for(k = j - 1; k > 0; --k)
{
if(s1[k-1] == ' ' && s1[k] == ' ')
continue;
else
printf("%c", s1[k]);
}
if(s1[k] == ' ')
printf("\n");
else
printf("%c\n", s1[k]);
}

return 0;

}

Post Reply

Return to “Bugs and suggestions”