0
点赞
收藏
分享

微信扫一扫

摸鱼日记2.15

Alex富贵 2022-02-15 阅读 74

学习目标:

一些暴力题
无脑就是无脑,没有脑袋。

学习内容:

十六进制转八进制

#include <bits/stdc++.h>
using namespace std;

int main(){
	
	int n;cin>>n;
	
	string str,all[16]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
	
	while(n>0){
		cin>>str;
		n--;
		string tmp,ans;
		for(int i=0;i<str.length();++i){
			if(str[i]<='9'){
				tmp+=all[str[i]-'0'];
			}else{
				tmp+=all[str[i]-'A'+10];
			}
		}

		
		if(tmp.length()%3==1)
			tmp = "00"+tmp;
		else if(tmp.length()%3==2)
			tmp = "0"+tmp;

		for(int i=0;i<tmp.length();){
			char ch = ((tmp[i++]-'0')*4+(tmp[i++]-'0')*2+(tmp[i++]-'0')*1)+'0';
			if(ans.length()==0&&ch=='0')continue;
			ans+=ch;
		}
		cout<<ans<<endl;
	}
	
	
	
	return 0;
}

十六进制转十进制

#include <bits/stdc++.h>
using namespace std; 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	string str;
	cin>>str;
	long long ans = 0;
	for(int i=0;i<str.length();++i){
		ans*=16;
		if(str[i]>'9'){
			ans+=(str[i]-'A'+10);
		}else{
			ans+=(str[i]-'0');
		}
	} 
	cout<<ans<<endl;
	
	return 0;
}

十进制转十六进制

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	
	long long n;
	cin>>n;
	if(n==0){
		cout<<"0"<<endl;return 0;
	}
	long long x;
	string ans;
	char ch;
	while(n!=0){
		x = n%16;
		if(x<10){
			ch = x+'0';
		}else{
			ch = x-10+'A';
		}
		ans+=ch;
		n/=16;
	}
	string res;
	for(int i=ans.size()-1;i>=0;--i)
		res+=ans[i];
	cout<<res<<endl;
	
	
	return 0;
}

杨辉三角形

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	
	int n;cin>>n;
	int arr[n][n];
	arr[0][0]=1,arr[1][0]=1,arr[1][1]=1; 
	cout<<1<<endl;
	cout<<1<<" "<<1<<endl;
	for(int i=2;i<n;++i){
		for(int j=0;j<=i;++j){
			if(j==0||j==i)
				arr[i][j]=1;
			else{
				arr[i][j] = arr[i-1][j-1]+arr[i-1][j];
			}
		}
		for(int j=0;j<=i;++j){
			cout<<arr[i][j]<<" ";
		}
		cout<<endl;
	}
	
	return 0;
}

和老婆在一起的第二天,约定要坚持3650天,这两天越来越爱她了。这种感觉也让人清醒,心情开朗。很抱歉没有好好陪她,不能好好对她。田田,真好听的名字。

举报

相关推荐

摸鱼日记2.5

摸鱼日记2.20

摸鱼日记1.24

摸鱼日记1.19

摸鱼日记1.31

摸鱼日记1.29

2.15 回溯

2.15 每日总结

0 条评论