itoa函数用法

#include<cstdlib>
#include<cstdio>
int main() { int num = 10; char str[100]; itoa(num, str, 2); printf("%s\n", str); return 0; }
itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是目标字符串,第三个参数是转移数字时所用 的基数。在上例中,转换基数为10。10:十进制;2:二进制……
于是想到了一个十进制转二进制的方法:
#include<cstdlib>
#include<cstdio>
int main() { int num = 10; char str[100]; int n = atoi(itoa(num, str, 2)); printf("%d\n",n); return 0; }
先把num转换为二进制的字符串,再把该字符串转换为整数。
 
#include <iostream>
using namespace std;
string a,l=""; char s[50]; int top=-1;
int main()
{
	cin>>a;
	for (int i=0;i<a.size();++i){
		if (a[i]>='0' && a[i]<='9' || a[i]>='a' && a[i]<='z')
			l+=a[i];
		if (a[i]=='(')
			s[++top]=a[i];
		if (a[i]==')'){
			while (s[top]!='(')
				l+=s[top--];
			top--;
		}
		if (a[i]=='+' || a[i]=='-'){
			while (top>=0 && (s[top]=='+' || s[top]=='-' || s[top]=='*' || s[top]=='/'))
				l+=s[top--];
			s[++top]=a[i];
		}
		if (a[i]=='*' || a[i]=='/'){
			while (top>=0 && (s[top]=='*' || s[top]=='/'))
				l+=s[top--];
			s[++top]=a[i];
		}
	}
	while (top>=0)
		l+=s[top--];
	cout<<l<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值