Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #include <stdlib.h> using namespace std; /* #################################################################### # Tim thu khi biet ngay thang nam # #################################################################### */ // Kiem tra ngay hop le bool check_date(int day, int month) { if ((month == 2) && (day > 0) && (day < 30)) { return true; } if (( (month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12) ) && ((day > 0) && (day < 32))) { return true; } if (( (month == 4) || (month == 6) || (month == 9) || (month == 11) ) && ((day > 0) && (day < 31))) { return true; } return false; } // Kiem tra thang hop le bool check_month(int month) { if ((month > 0) && (month < 13)) { return true; } else { return false; } } // Kiem tra nam hop le bool check_year(int year) { if ((year > 999) && (year < 10000)) { return true; } else { return false; } } // Kiem tra nam nhuan bool check_leap_year(int year) { if (((year % 4) == 0) && ((year % 100) != 0)) { return true; } else if ((year % 400) == 0) { return true; } else { return false; } } // Tim chính xác thu theo ngày tháng nam dã biêt // // http://en.wikipedia.org/wiki/Julian_day#Calculation // const char* get_day(int day, int month, int year) { int JMD; JMD = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5) + (365 * (year + 4800 - ((14 - month) / 12))) + ((year + 4800 - ((14 - month) / 12)) / 4) - ((year + 4800 - ((14 - month) / 12)) / 100) + ((year + 4800 - ((14 - month) / 12)) / 400) - 32045) % 7; //cout << JMD; const char* weekday[] = { "2", "3", "4", "5", "6", "7", "8" }; return weekday[JMD]; } int main() { // Khai bao bien int year, month, date, x, y; cout << "\n[+] CHUONG TRINH TINH THU KHI BIET NGAY THANG NAM."; // Take Inputs cout << "\n[+] Vui long nhap nam [YYYY] : "; cin >> year; // cout << "\n[+] Kiem tra [YYYY] : "; // verify year if (check_year(year)) { cout << "[-] Xac nhan!"; } else { cout << "\n\t [-] Nhap sai!\n"; exit(0); } cout << "\n[+] Vui long nhap thang [MM] : "; cin >> month; // verify month if (check_month(month)) { cout << "[-] Xac nhan!"; } else { cout << "[-] Nhap sai!"; exit(0); } cout << "\n[+] Vui long nhap ngay [DD] : "; cin >> date; // verify date if (check_date(date, month)) { cout << "[-] Xac nhan!\n\n"; } else { cout << "[-] Nhap sai!"; exit(0); } cout << "[+] Ngay : " << date << ", Thang : " << month << ", Nam : " << year << " [ "; if (check_leap_year(year)) { cout << "Nam nhuan" << " ]"; } else { cout << "Khong phai nam nhuan" << " ]"; } cout << "\n[-] Ngay trong tuan: "; cout << get_day(date, month, year); cout << "\n\n"; int date1, date2, m1, m2, y1, y2; cout << "Nhap ngay thang nam 1"; cin >> date1 >> m1 >> y1; cout << "Nhap ngay thang nam 2"; cin >> date2 >> m2 >> y2; int i; if (m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 || m1 == 12) { if (m1 < m2) { for ( i = date1;i < 31;i++) { if (get_day(i, m1, year) == "2") { cout << "that day" << endl; cout << year << " " << m1 << " " << i; break; } if (i == 31) { m1++; i = 1; } } } } else if (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 12) { if (m1 < m2) { for ( i = date1;i < 30;i++) { if (get_day(i, m1, year) == "2") { cout << "that day" << endl; cout << year << " " << m1 << " " << i; break; } if (i == 30) { m1++; i = 1; } } } } //ngang trên là in ra ngày thứ 2 gần nhất được rồi .còn giải quyết từ ngày 1/4 đến 31/4 in ra các ngày thứ 2 thì chưa nè while (i < date2 && m1 < m2) { cout << year << " " << m1 << " " << i; if (m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 || m1 == 12) { if (m1 < m2) { for (i;i < 31;i+=7) { if (i > 31) { m1++; i = i - 31; } } } } else if (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 12) { if (m1 < m2) { for (i = date1;i < 31;i += 7) { if (i > 31) { m1++; i = i - 31; } } } } } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत