cheraas
BAN USERI guess, the following solution would be the most efficient one. Since it will run year2-year1 times.
If you have any comments, let me know.
#include <stdio.h>
#include <stdlib.h>
const int n[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int process_date (int year, int input_month, int input_day) {
int t, month, day;
t = year % 100;
month = (t % 10) * 10 + (t / 10);
if ( month < 1 || month > 12 )
return 1;
if ( input_month && month > input_month)
return 1;
t = year / 100;
day = (t % 10) * 10 + (t / 10);
if ( input_day && day > input_day)
return 1;
int max_day;
if ( (year % 4 == 0) && ( month == 2) ) {
max_day = n[month-1] + 1;
}
else
max_day = n[month-1];
if (day <= max_day) {
printf ("palindrome year %d\n", year);
}
return 0;
}
int main (int args, char *argv[]) {
int m1 = 1, d1 = 8, y1 = 9020;
int m2 = 1, d2 = 2, y2 = 9033;
int i;
process_date(y1, m1, d1);
for ( i = y1+1; i < y2; i++) {
process_date(i, 0, 0);
}
process_date(y2, m2, d2);
return 0;
}
RepAayshaRosie, HTML Freshers at Abs india pvt. ltd.
Aaysha , a book editor with 4 years of experience with increasing readership and developing skilled writers. At the Daily Record ...
Reppaytonmorrison48, Data Scientist at ADP
I am working as a date entry keyar . I have many years of experience . The data entry manager is primarily ...
The following piece of code, generates all possible substrings and checks for a sequence. For example:
- cheraas October 30, 2012From "123123qs",
during the first round, the substrings "1", "12", "123", "1231" are generated and compared.
int main () {
char a[] = "123123qs";
char buff[256];
int a_lenth = strlen(a);
int i, j, match_found = 0;
for (i = 0; i < a_lenth; i++) {
for (j = i; j < i+(a_lenth-i)/2; j++) {
memset (buff, 0, sizeof (buff));
memcpy (buff, a+i, j-i+1);
if (memcmp (buff, a+j+1, j-i+1)) {
continue;
} else {
match_found = 1;
printf ("Not a valid password\n");
break;
}
}
if (match_found) {
break;
}
}
return 0;
}