Hej. Ja zrobiłem to tak. Na moim kopi działa dobrze wyniki są poprawne.
Na SPOJ nie działa. Dlaczego?
#include <iostream>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
int main()
{
string pesel;
string pomocnicza="";
double wynik=0;
int tab[11];
short ile;
cin >> ile;
for (int k = 0; k < ile; k++)
{
cin >> pesel;
for (int i = 0; i < 11; i++)
{
pomocnicza.push_back(pesel[i]);
tab[i] = atoi(pomocnicza.c_str());
pomocnicza = "";
}
tab[0] = tab[0] * 1;
tab[1] = tab[1] * 3;
tab[2] = tab[2] * 7;
tab[3] = tab[3] * 9;
tab[4] = tab[4] * 1;
tab[5] = tab[5] * 3;
tab[6] = tab[6] * 7;
tab[7] = tab[7] * 9;
tab[8] = tab[8] * 1;
tab[9] = tab[9] * 3;
tab[10] = tab[10] * 1;
for (int j = 0; j < 11; j++)
{
wynik += tab[j];
}
if ((wynik - ((floor(wynik / 10)) * 10)) == 0)
cout << "D" << endl;
else
cout << "N" << endl;
}
return 0;
}