标签:style io ar color os 使用 sp for on
2 1.000+2/4= ((1+2)*5+1)/4=
1.000 2 4 / + = 1 2 + 5 * 1 + 4 / =
代码:
#include<stdio.h>
int main()
{
	int T,i,top;
	char str[1005],ch[1005];
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",str);
		top=-1;
		for(i=0;str[i]!=‘\0‘;i++)
		{
			if(str[i]>=‘0‘&&str[i]<=‘9‘)
			{
				while((str[i]==‘.‘)||(str[i]>=‘0‘&&str[i]<=‘9‘))
				{
					printf("%c",str[i]);
					i++;
				}
				printf(" ");
			}
			if(str[i]==‘=‘)
				break;
			if(str[i]==‘)‘)
			{
				while(top>=0&&(ch[top]!=‘(‘))
				{
					printf("%c ",ch[top]);
					top--;
				}
				top--;
			}
			else if(str[i]==‘(‘)
			{
				top++;
				ch[top]=str[i];
			}
			else if(str[i]==‘*‘||str[i]==‘/‘)
			{
				while((ch[top]==‘*‘)||(ch[top]==‘/‘))
				{
					printf("%c ",ch[top]);
					top--;
				}
				top++;
				ch[top]=str[i];
			}
			else
			{
				while(top>=0&&(ch[top]!=‘(‘))
				{
					printf("%c ",ch[top]);
					top--;
				}
				top++;
				ch[top]=str[i];
			}
		}
		while(top>=0)
		{
			printf("%c ",ch[top]);
			top--;
		}
		printf("=\n");
	}
	return 0;
}
标签:style io ar color os 使用 sp for on
原文地址:http://blog.csdn.net/qq_16997551/article/details/41871063