1 solutions

  • 0
    @ 2025-12-11 7:44:50
    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    signed main() {
    	int q;
    	cin >> q;
    	int nf[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	int nf2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	int nf3[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 21, 30, 31};
    //	int nf4[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	int total1 = 3 * 365 + 366;
    	int total2 = 100 * (3 * 365 + 366) - 3;
    	int gyq = (4713 / 4) * total1 + 366;
    	int gyh1581 = (1580 / 4) * total1 + 365;
    	int n;
    
    	while (q--) {
    		cin >> n;
    		n++;
    		if (n <= gyq) {
    			int po = n / total1;
    			int totalyear = 0;
    			totalyear = po * 4;
    			int res = n % total1;
    			int yf = 0;
    
    
    			if (res <= 366 && res > 0) {
    				//	cout << endl;
    				for (int i = 1; i <= 12; i++) {
    
    					if (res - nf2[i] > 0) {
    						res -= nf2[i];
    
    						yf = i;
    						//	cout<<res<<" "<<yf<<endl;
    					} else {
    						break;
    					}
    
    
    				}
    				cout << res << " " << yf + 1 << " " << 4713 - totalyear << " " << "BC" << endl;
    			} else if (res == 0) {
    				totalyear--;
    				res = 365;
    				
    				for (int i = 1; i <= 12; i++) {
    
    					if (res - nf[i] > 0) {
    						res -= nf[i];
    						yf = i;
    					} else {
    						break;
    					}
    
    
    				}
    				cout << res << " " << yf + 1 << " " << 4713 - totalyear << " " << "BC" << endl;
    
    
    			}
    
    
    			else {
    				res -= 366;
    				totalyear++;
    				totalyear += res / 365;
    				res -= res / 365 * 365;
    				if (res == 0) {
    					totalyear--;
    					res = 365;
    				}
    
    				//	cout<<res<<totalyear;
    				for (int i = 1; i <= 12; i++) {
    
    					if (res - nf[i] > 0) {
    						res -= nf[i];
    						yf = i;
    					} else {
    						break;
    					}
    
    
    				}
    				cout << res << " " << yf + 1 << " " << 4713 - totalyear << " " << "BC" << endl;
    
    			}
    		} else {
    			n -= gyq;
    			if (n <= gyh1581) {
    				int po = n / total1;
    				int totalyear = 1;
    				totalyear =totalyear+ po * 4;
    				int res = n % total1;
    				int yf = 0;
    				if (res <= 1095) {
    					totalyear += res / 365;
    					res -= res / 365 * 365;
    					if(res==0){
    						totalyear--;
    						res=365;
    					}
    					for (int i = 1; i <= 12; i++) {
    
    						if (res - nf[i] > 0) {
    							res -= nf[i];
    							yf = i;
    						} else {
    							break;
    						}
    
    
    					}
    					cout << res << " " << yf + 1 << " " << totalyear << endl;
    
    				} else {
    					totalyear += 3;
    					res -= 1095;
    					for (int i = 1; i <= 12; i++) {
    
    						if (res - nf2[i] > 0) {
    							res -= nf2[i];
    							yf = i;
    						} else {
    							break;
    						}
    
    
    					}
    					cout << res << " " << yf + 1 << " " << totalyear << endl;
    				}
    			} else {
    				n -= gyh1581;
    				if (n <= 355) {
    					int totaltear = 1582;
    					int res = n;
    					int yf = 0;
    					for (int i = 1; i <= 12; i++) {
    
    						if (res - nf3[i] > 0) {
    							res -= nf3[i];
    							yf = i;
    						} else {
    							break;
    						}
    
    
    					}
    					if (yf == 9) {
    						if (res <= 4)
    							cout << res << " " << yf + 1 << " " << totaltear << endl;
    						else
    							cout << res + 10 << " " << yf + 1 << " " << totaltear << endl;
    
    					} else {
    						cout << res << " " << yf + 1 << " " << totaltear  << endl;
    					}
    
    				} else {
    					n -= 355;
    					int totaltear = 1583;
    					int res = n % total2;
    
    					totaltear += n / total2 * 400;
    					if(res==0){
    						totaltear--;
    						res=365;
    					}
    					int temptear = 365;
    					while (res - temptear > 0) {
    						res -= temptear;
    						totaltear++;
    						if ((totaltear % 4 == 0 && totaltear % 100 != 0) || (totaltear % 400 == 0))
    							temptear = 366;
    						else temptear = 365;
    					}
    					int yf = 0;
    
    					if (temptear == 365) {
    			
    						for (int iii = 1; iii <= 12; iii++) {
    									
    							if (res - nf[iii] > 0) {
    								res -= nf[iii];
    								yf = iii;
    							} else {
    								break;
    							}
    						}
    						cout << res << " " << yf + 1 << " " << totaltear << endl;
    					} else {
    
    						for (int i = 1; i <= 12; i++) {
    
    							if (res - nf2[i] > 0) {
    								res -= nf2[i];
    								yf = i;
    							} else {
    								break;
    							}
    
    
    						}
    						cout << res << " " << yf + 1 << " " << totaltear << endl;
    
    					}
    
    
    				}
    
    
    			}
    
    		}
    
    	}
    
    
    
    }
    
    
    • 1

    Information

    ID
    6
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    8
    Accepted
    2
    Uploaded By