uva 621 - Secret Research

November 7, 2012
Uva

At a certain laboratory results of secret research are thoroughly encrypted. A result of a single experiment is stored as an information of its completion:  

positive result', negative result’, experiment failed' or experiment not completed’

 

The encrypted result constitutes a string of digits S, which may take one of the following forms:

  (A sample result S35 means that if we add digits 35 from the right hand side to a digit sequence then we shall get the digit sequence corresponding to a failed experiment)  

You are to write a program which decrypts given sequences of digits.

 

A integer n stating the number of encrypted results and then consecutive nlines, each containing a sequence of digits given as ASCII strings.   For each analysed sequence of digits the following lines should be sent to output (in separate lines):   In case the analysed string does not determine the experiment result, a first match from the above list should be outputted.           话说这道水题开始没看懂。。。。不多说,看代码就可以看懂

拙劣的代码

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void)
{
    char a[1000];

    while (cin >> a)
    {
        int len = strlen(a);
        if (!strcmp(a, "1") || !strcmp(a, "4") || !strcmp(a, "78"))
            cout << '+' << endl;
        else
        {
            if (a[len-1] == '5' && a[len-2] == '3') cout << '-' << endl;
            else if (a[len-1] == '4' & a[0] == '9') cout << '*' << endl;
            else if (a[0] == '1' && a[1] == '9' && a[2] == '0') cout <<'?'
            << endl;
        }
    }

    return 0;
}


comments powered by Disqus