【蓝桥杯】 天干地支*(人文知识)

穿越隧道

有个关于天干地支的计算方法,参考于百度百科
(年份- 3)/10余数对天干:如1894-3=1891 ,1891除以10余数是1即为甲;
(年份- 3)/12余数对地支:如1894-3=1891 ,1891除以12余数是7即为午,即1894年是甲午年。
因代码中的甲和子是从下标0开始的,所以年份减4;

正确代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
string s;
int n,k;
struct node{
	string st;
	int len;
}st[N];
int j;
string tg[10] = {"jia","yi","bing","ding","wu","ji","geng","xin","ren","gui"};

string dz[12] ={"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"};  
int main(){
	int n;
	cin >> n;
	int flag = 1;
	cout << tg[(n - 4)%10];
	cout << dz[(n - 4)%12]; 
	return 0;
} 

含错误思路的代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
string s;
int n,k;
//string st[N];
struct node{
	string st;
	int len;
}st[N];
int j;
string tg[10] = {"jia","yi","bing","ding","wu","ji","geng","xin","ren","gui"};

string dz[12] ={"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"};  
int main(){
	int n;
	cin >> n;
//	vector<int> c;
	int flag = 1;
//	while(n){
		
//		n %= 10;
		cout << tg[(n - 4)%10];
//		n -= n/10;
		cout << dz[(n-4)%12]; 
//		n /= 12;
//		n %= 12;
//		if(flag){
//			cout << dz[n/60%10];
			c.push_back(n%12);
//			n/=10;
//			flag = 0;
//		}
//		else{
//			cout << tg[n%12];
			c.push_back(n%10);
//			n/=12;
//			flag = 1;
//		}
		
//	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值