2021-02-28

十六进制转八进制

#include<stdio.h>

#include<string.h>
int main()
{
	int n,i,b,k,a,c,d,m,l;
	char s[10][100001],d16[16][5]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"},out[140000]={},z[13]={};
	scanf("%d",&n);
	for(b=0;b<n;b++)
		scanf("%s",s[b]);
	for(b=0;b<n;b++)
		{
			k=0;d=1;m=0;
			l=strlen(s[b]);
			a=3-l%3;
			if(a==3)	d=0;
			for(i=0;i<l;i++)
			{
				if(65<=s[b][i])
					s[b][i]-=7;
				if(d)
					if(a==1){
						strcat(z,"0000");k=k+4;ok=0;
					}else if(a==2){
						strcat(z,"00000000");k=k+8;ok=0;
					}
				z[k++]=d16[s[b][i]-48][0];
				z[k++]=d16[s[b][i]-48][1];
				z[k++]=d16[s[b][i]-48][2];
				z[k++]=d16[s[b][i]-48][3];
				if(k==12)
				{
					for(c=0;c<12;m++)
						out[m]=((z[c++]-48)*4+(z[c++]-48)*2+(z[c++]-48)*1)+48;
					z[0]='\0';k=0;
				}
			}
			for(;k<3;k++)
				if(out[k]!=48)	break;
			for(;k<m;k++)
				printf("%c",out[k]);
			putchar('\n');
		}
	return 0;
 }

视频学习:关系运算符和关系表达式

关系运算符eg:bool

#include<iostream>
using namespace std;
int main()
{
	int n1 = 4,n2 = 5,n3;
	n3 = ( n1 > n2);
	cout << n3 << ",";
	n3 = ( n1 < n2);
	cout << n3 << ",";
	n3 = (n1 != 4);
	cout << n3 << ",";
	n3 = (n1 == 5);
	cout n3;
	return 0;
}

逻辑运算符和逻辑表达式:逻辑运算符用于表达式的逻辑操作,有&&,||,!三种,操作的结果是true,false

#include<iostream>
using namespace std;
int main()
{
	int a =0,b =1;
	bool n = (a++) && (b++);
	cout << a <<"," << b << endl;
	n = a ++ && b ++;
	cout << a << "," << b << endl;
	n = a ++ || b ++;
	cout << a << "," << b << endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值