ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1404. Easy to Hack!

why got WA, I have tested with several cases! thanks!
Posted by jacksparo 8 Aug 2009 19:05
#include <iostream>
using namespace std;

int main(void)
{
    char encry[101];
    int temp[101];
    char dencry[101];

    memset(encry, 0, 101*sizeof(char));
    memset(temp, 0, 101*sizeof(int));
    memset(dencry, 0, 101 * sizeof(char));

    fgets(encry, 101, stdin);

    for (int i=0; i<strlen(encry)-1; i++)
    {
        temp[i] = encry[i] - 'a';
    }

    if (temp[0] < 5)
    {
        temp[0] += 26;
    }

    for (int i=1; i<strlen(encry)-1; i++)
    {
        while (temp[i] < temp[i-1])
        {
            temp[i] += 26;
        }
    }

    for (int i=strlen(encry)-1; i>0; i--)
    {
        temp[i] = temp[i] - temp[i-1];
        dencry[i] = temp[i] + 'a';
    }

    temp[0] -= 5;
    dencry[0] += temp[0] + 'a';

    for (int i=0; i<strlen(encry)-1; i++)
    {
        cout << dencry[i];
    }
    cout << endl;
    return 0;
}
Re: why got WA, I have tested with several cases! thanks!
Posted by jacksparo 8 Aug 2009 20:35
got AC, after use n instead of strlen(encry)-1, where n is the number of characters.

Caused by difference of strlen between compilers I think.