/** (c) 2012 Michał (Foxbond) Chraniuk */
#include <iostream>
#include <cstring>
using namespace std;
int main () {
char _pesel[200];
short pesel[11];
int sum = 0;
int day, month, year;
cout << "Podaj pesel aby zweryfikowac: ";
cin >> _pesel;
if (strlen(_pesel) != 11){
cout << "Bledny pesel! (pesel musi miec 11 cyfr)\n";
return 0;
}
for (short i = 0; i < 11; i++){
if (_pesel[i] < 48 || _pesel[i] > 57){
cout << "Bledny pesel! (pesel moze zawierac same liczby)\n";
return 0;
}
pesel[i] = _pesel[i] - 48;
}
sum = 1*pesel[0]+3*pesel[1]+7*pesel[2]+9*pesel[3]+1*pesel[4]+3*pesel[5]+7*pesel[6]+9*pesel[7]+1*pesel[8]+3*pesel[9];
sum %= 10;
sum = 10-sum;
if (sum != pesel[10]){
cout << "Bledny pesel! (zla suma kontrolna)\n";
return 0;
}
year = 10 * pesel[0];
year += pesel[1];
month = 10 * pesel[2];
month += pesel[3];
if (month > 80 && month < 93) {
month -= 80;
year += 1800;
}else if (month > 20 && month < 33) {
month -= 20;
year += 2000;
}else if (month > 40 && month < 53) {
month -= 40;
year += 2100;
}else if (month > 60 && month < 73) {
month -= 60;
year += 2200;
}else if (month > 0 && month < 13){
year += 1900;
}else{
cout << "Bledny pesel! (Nieprawidlowo zakodowany rok)\n";
return 0;
}
day = 10 * pesel[4];
day += pesel[5];
if ((day >0 && day < 32) &&
(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)) {
}else if ((day >0 && day < 31) &&
(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)) {
}else{
cout << "Bledny pesel! (Nieprawidlowy miesiac)\n";
return 0;
}
cout << "pesel jest poprawny!\nData urodzenia: " << day <<"-"<< month <<"-"<< year <<"\nPlec: ";
if (pesel[9] % 2 == 1) {
cout << "Mezczyzna\n";
}else {
cout << "Kobieta\n";
}
return 0;
}
> Back