相当强悍

源代码在线查看: opration prior new.cpp

软件大小: 133 K
上传用户: ok34090512
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Opration Prior New.cpp : Defines the entry point for the console application.
				//
				
				#include "stdafx.h"
				#include 
				#include 
				#include 
				#include 
				#include 
				
				int check=10;
				
				int change(char *cd1,int a){
				  int i,o=0,c,j;
				  for(i=0;i				    c=1;
				    for(j=a-1;j>=i;j--){
				      if(j==i) c=1*c;
				      else c=c*10;
				    }
				    o=o+(cd1[i+1]-48)*c;
				  }
				  return(o);
				}
				
				int Count(int a,int b,char c){
				  int dd;
				  switch(c){
				    case '*':dd=a*b;break;
				    case '/':dd=a/b;break;
				    case '+':dd=a+b;break;
				    case '-':dd=a-b;break;
				    default :printf("Error!");
				  }
				  return(dd);
				}
				
				char compare(char a,char b)
				{
				  if(a=='*'&&b=='/') return('>');
				  if(a=='/'&&b=='*') return('>');
				  if(a=='+'&&b=='-') return('>');
				  if(a=='-'&&b=='+') return('>');
				  if(a=='*'&&b=='+') return('>');
				  if(a=='*'&&b=='-') return('>');
				  if(a=='/'&&b=='+') return('>');
				  if(a=='/'&&b=='-') return('>');
				  if(a=='+'&&b=='*') return('				  if(a=='+'&&b=='/') return('				  if(a=='-'&&b=='*') return('				  if(a=='+'&&b=='*') return('				  if(a=='*'&&b=='(') return('				  if(a=='/'&&b=='(') return('				  if(a=='+'&&b=='(') return('				  if(a=='-'&&b=='(') return('				  if(a=='*'&&b==')') return('>');
				  if(a=='/'&&b==')') return('>');
				  if(a=='+'&&b==')') return('>');
				  if(a=='-'&&b==')') return('>');
				  if(a=='('&&b=='*') return('				  if(a=='('&&b=='/') return('				  if(a=='('&&b=='+') return('				  if(a=='('&&b=='-') return('				  if(a==')'&&b=='*') return('>');
				  if(a==')'&&b=='/') return('>');
				  if(a==')'&&b=='+') return('>');
				  if(a==')'&&b=='-') return('>');
				  if(a=='*'&&b==';') return('>');
				  if(a=='/'&&b==';') return('>');
				  if(a=='+'&&b==';') return('>');
				  if(a=='-'&&b==';') return('>');
				  if(a=='#'&&b=='*') return('				  if(a=='#'&&b=='/') return('				  if(a=='#'&&b=='-') return('				  if(a=='#'&&b=='+') return('				  if(a=='#'&&b==';') return('=');
				  if(a=='('&&b=='(') return('				  if(a==')'&&b==')') return('>');
				  if(a==')'&&b=='#') return('>');
				  if(a=='*'&&b=='*') return('>');
				  if(a=='/'&&b=='/') return('>');
				  if(a=='+'&&b=='+') return('>');
				  if(a=='-'&&b=='-') return('>');
				  if(a=='('&&b==')') return('=');
				  if(a==')'&&b==';') return('>');
				  return 0;
				}
				
				
				int main(int argc, char* argv[])
				{
					FILE *fp,*fq;
					char c1[100],c;
					char chuan[100];
					int c2[100],i=0,j=0,result,ii=0,a,b;
					fp=fopen("document1.txt","wr");
					if(!fp) printf("Open File Error!");
					else
					{
						printf("Please Input biao da shi :\n");//以“;#”结尾,不能以(开头
						while((c=getchar())!='#') fprintf(fp,"%c",c);
						fclose(fp);
				//		cifa();
				//		yufa();
						if(check==10)
						{
				//			printf("yufa OK!");
							fp=fopen("document1.txt","r");
							fq=fopen("document3.txt","w");
							if(!fq||!fp) printf("file not open!");
							else
							{
								fscanf(fp,"%c",&c);
								fprintf(fq," %c ",c);
							//	fscanf(fp,"%c",&c);
								while(c!=';')
								{
									fscanf(fp,"%c",&c);
									while(c!='+'&&c!='-'&&c!='*'&&c!='/'&&c!='('&&c!=')'&&c!=';')
									{
										fprintf(fq,"%c",c);
										fscanf(fp,"%c",&c);
									}
									fprintf(fq," %c ",c);
								}
								fclose(fp);
								fclose(fq);
							}
						}
						else
						{
							printf("yufa Error!");
					
						}
					}
				
					for(i=0;i					c1[j++]='#';
					fp=fopen("document3.txt","r");
					fscanf(fp,"%c",&c);
					i=0;
					while(c!=';'||c1[j-1]!='#')
					{
						if(c!='*'&&c!='/'&&c!='+'&&c!='-'&&c!='('&&c!=')'&&c!=';'&&c!=' ')
						{
							i=0;
							while(c>='0'&&c							{
								i++;
								chuan[i]=c;
								fscanf(fp,"%c",&c);
							}
							ii++;
							c2[ii]=change(chuan,i);
						}
						if(c==' ') fscanf(fp,"%c",&c);
						if(c=='*'||c=='/'||c=='+'||c=='-'||c=='('||c==')'||c==';')
						{
							switch(compare(c1[j-1],c))
							{
								case '									c1[j++]=c;
									fscanf(fp,"%c",&c);
									break;
								case '=':
									j=j-1;
									fscanf(fp,"%c",&c);
									break;
								case '>':
									if(ii>=2)
									{
										a=c2[ii];ii=ii-1;
										b=c2[ii];
										result=Count(b,a,c1[--j]);
										c1[j]=c;
										c2[ii]=result;
										break;
									}
									else
									{
										c1[j++]=c;
										fscanf(fp,"%c",&c);
										break;
									}
							}
				
						}
					}
					printf("\nresult->%d\n",result);
				
					return 0;
				}
							

相关资源