none
控制台问题:用回车结束报数,怎么把答案显示在报数行 RRS feed

答案

  • 看你的意思,源代码是刚需。JCP源代码可是我花了一个多月,研究出来的

    ///<summary>加减乘除方计算</summary><param name="str"></param><returns></returns>
    		public string JCP(string str){
    			var dp = new DataPack();
    			string[] ar,arp,arm;
    			var jj = dp.Found(str,"-","+");
    			SortedList<int,string> cf;
    			int s = 0, w = 0, xz = 0;
    			List<double> num = new List<double>();
    			ar=new string[0];
    			try{
    				return $"{new StriTo().Str2Num2(str)}";
    			}catch{
    				if(str[0]!='-'&&str[0]!='+'){
    					s++;
    					Array.Resize(ref ar,s);
    					ar[s-1]="+";
    				}
    				for(int v = 0;v<str.Length;){
    					if(jj.ContainsKey(v)){
    						if(w!=0){
    							w++;
    							switch(PlusOmssion(str.Substring(xz,w+1))){
    								case '+': case '-': v++; break;
    								case '\x6de':
    								s++; w++;
    								Array.Resize(ref ar,s);
    								ar[s-1]=PlusOmssion(str.Substring(xz,w-1)).ToString();
    								w=0; v++;
    								break;
    							}
    						} else if(w==0){
    							xz=v; w++;
    							switch(PlusOmssion(str.Substring(xz,w+1))){
    								case '+': case '-': v++; break;
    								case '\x6de':
    								s++; w++;
    								Array.Resize(ref ar,s);
    								ar[s-1]=PlusOmssion(str.Substring(xz,w-1)).ToString();
    								w=0; v++; break;
    							}
    						}
    					} else{
    						s++; Array.Resize(ref ar,s); ar[s-1]=str[v].ToString(); v++;
    					}
    				}
    				s=0;
    				arp=new string[0];
    				w=0; s=0;
    				for(int va = 0;va<ar.Length;va++){//检验以加减拆开的
    					if(ar[va]=="+"||ar[va]=="-"){
    						if(arp==null||arp.Length==0){
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,1));
    							s++;
    						} else{
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,va-s));
    							s=va;
    							w++;
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,1));
    							s++;
    							w++;
    						}
    					}
    					if(va==ar.Length-1){
    						Array.Resize(ref arp,arp.Length+1);
    						arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s));
    						w++;
    					}
    				}
    				s=0; w=0; arm=new string[0]; xz=0;
    
    				for(int vb = 0;vb<arp.Length;vb++){
    					cf=dp.Found(arp[vb],dp.ToStringArray("^⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ ⁱ"));
    					try{num.Add(stto.Str2Dou(arp[vb]));}catch{
    						if(arp[vb]=="+"||arp[vb]=="-"){ }else{
    					s=0;w=0;
    						arm=new string[0];
    						for(int vd = 0;vd<arp[vb].Length;vd++){
    							if(arp[vb][vd]=='\xd7'||arp[vb][vd]=='\xf7'){
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s,vd-s);
    								s=vd;
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s,1);
    								s+=1;
    							}
    							if(vd==arp[vb].Length-1){
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s);
    							}
    						}
    						double[] nc = new double[0];//算出乘除号旁边的数,再进行乘除
    						foreach(string vv in arm){
    
    							cf=dp.Found(vv,dp.ToStringArray("^⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿⁱ"));
    							if(vv!="\xd7"&&vv!="\xf7"){
    								if(cf.Count==0){
    									try{
    										Array.Resize(ref nc,nc.Length+1);
    										nc[nc.Length-1]=stto.Str2Dou(vv);
    									} catch{Array.Resize(ref nc,nc.Length-1);}
    								} else{
    									Array.Resize(ref nc,nc.Length+1);
    									nc[nc.Length-1]=stto.Str2Dou(new ShuXue().Logo_Pow(vv));
    								}
    							}
    						}
    						double ne = nc[0]; s=1;
    						for(int vf = 0;vf<arm.Length;vf++){
    							try{ 
    							if(arm[vf]=="\xd7"){
    								ne*=nc[s];
    								s++;
    							} else if(arm[vf]=="\xf7"){
    								ne/=nc[s];
    								s++;
    							}}catch{ }
    						}
    						num.Add(ne);
    					}}
    				}
    			}
    			s=0;double j=0;
    			for(int h = 0;h<arp.Length/2;h++){
    				try{
    					if(arp[s].ToString()=="-") j-=num[h];
    					else if(arp[s].ToString()=="+") j+=num[h];
    					s+=2;
    				} catch{ }
    			}
    			return $"{j}";
    		}

    如果有绩效,分我一半嘛。

    • 已标记为答案 czhch 2022年3月29日 21:12
    2022年3月29日 7:46

全部回复

  • 如题。

    我想以回车结束输入,但输出字符位置还在输入那行。

    你好 czhch,

    请粘贴出您目前的代码,我会帮您解决。

    以您目前的描述,我无法得知您目前的具体错误。

    Best Regards,

    Jiale


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2022年3月28日 2:22
  • static void Main(){
    	Console.OutputEncoding=Encoding.Unicode;
    	Console.InputEncoding=Encoding.Unicode;
    	Console.WindowHeight=8;
    	Console.WindowWidth=20;
    	while(true){
    		Console.Write("请输入算式\r\n");string raded;
    		raded=Console.ReadLine();
    		raded=raded.Replace('/','\xf7');
    		raded=raded.Replace('*','\xd7');
    		Console.Write("{0}{1}{2}","\b\b\b","=",new ShuXue().JCP(raded));
    		Console.ReadKey();
    	}
    }

    我的想法是用\b往回删字符,运行失败。

    2022年3月28日 5:24
  • 你好 czhch,

    你能给我一个demo吗?

    例如:

    输入:1+2=

    输出:1+2=3

    顺便ShuXue这个自定义方法定义是什么?

    请把代码给全。

    Best Regards,

    Jiale


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2022年3月28日 6:48
  • 看你的意思,源代码是刚需。JCP源代码可是我花了一个多月,研究出来的

    ///<summary>加减乘除方计算</summary><param name="str"></param><returns></returns>
    		public string JCP(string str){
    			var dp = new DataPack();
    			string[] ar,arp,arm;
    			var jj = dp.Found(str,"-","+");
    			SortedList<int,string> cf;
    			int s = 0, w = 0, xz = 0;
    			List<double> num = new List<double>();
    			ar=new string[0];
    			try{
    				return $"{new StriTo().Str2Num2(str)}";
    			}catch{
    				if(str[0]!='-'&&str[0]!='+'){
    					s++;
    					Array.Resize(ref ar,s);
    					ar[s-1]="+";
    				}
    				for(int v = 0;v<str.Length;){
    					if(jj.ContainsKey(v)){
    						if(w!=0){
    							w++;
    							switch(PlusOmssion(str.Substring(xz,w+1))){
    								case '+': case '-': v++; break;
    								case '\x6de':
    								s++; w++;
    								Array.Resize(ref ar,s);
    								ar[s-1]=PlusOmssion(str.Substring(xz,w-1)).ToString();
    								w=0; v++;
    								break;
    							}
    						} else if(w==0){
    							xz=v; w++;
    							switch(PlusOmssion(str.Substring(xz,w+1))){
    								case '+': case '-': v++; break;
    								case '\x6de':
    								s++; w++;
    								Array.Resize(ref ar,s);
    								ar[s-1]=PlusOmssion(str.Substring(xz,w-1)).ToString();
    								w=0; v++; break;
    							}
    						}
    					} else{
    						s++; Array.Resize(ref ar,s); ar[s-1]=str[v].ToString(); v++;
    					}
    				}
    				s=0;
    				arp=new string[0];
    				w=0; s=0;
    				for(int va = 0;va<ar.Length;va++){//检验以加减拆开的
    					if(ar[va]=="+"||ar[va]=="-"){
    						if(arp==null||arp.Length==0){
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,1));
    							s++;
    						} else{
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,va-s));
    							s=va;
    							w++;
    							Array.Resize(ref arp,arp.Length+1);
    							arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s,1));
    							s++;
    							w++;
    						}
    					}
    					if(va==ar.Length-1){
    						Array.Resize(ref arp,arp.Length+1);
    						arp[arp.Length-1]=string.Concat(dp.JieQu(ar,s));
    						w++;
    					}
    				}
    				s=0; w=0; arm=new string[0]; xz=0;
    
    				for(int vb = 0;vb<arp.Length;vb++){
    					cf=dp.Found(arp[vb],dp.ToStringArray("^⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ ⁱ"));
    					try{num.Add(stto.Str2Dou(arp[vb]));}catch{
    						if(arp[vb]=="+"||arp[vb]=="-"){ }else{
    					s=0;w=0;
    						arm=new string[0];
    						for(int vd = 0;vd<arp[vb].Length;vd++){
    							if(arp[vb][vd]=='\xd7'||arp[vb][vd]=='\xf7'){
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s,vd-s);
    								s=vd;
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s,1);
    								s+=1;
    							}
    							if(vd==arp[vb].Length-1){
    								Array.Resize(ref arm,arm.Length+1);
    								arm[arm.Length-1]=arp[vb].Substring(s);
    							}
    						}
    						double[] nc = new double[0];//算出乘除号旁边的数,再进行乘除
    						foreach(string vv in arm){
    
    							cf=dp.Found(vv,dp.ToStringArray("^⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿⁱ"));
    							if(vv!="\xd7"&&vv!="\xf7"){
    								if(cf.Count==0){
    									try{
    										Array.Resize(ref nc,nc.Length+1);
    										nc[nc.Length-1]=stto.Str2Dou(vv);
    									} catch{Array.Resize(ref nc,nc.Length-1);}
    								} else{
    									Array.Resize(ref nc,nc.Length+1);
    									nc[nc.Length-1]=stto.Str2Dou(new ShuXue().Logo_Pow(vv));
    								}
    							}
    						}
    						double ne = nc[0]; s=1;
    						for(int vf = 0;vf<arm.Length;vf++){
    							try{ 
    							if(arm[vf]=="\xd7"){
    								ne*=nc[s];
    								s++;
    							} else if(arm[vf]=="\xf7"){
    								ne/=nc[s];
    								s++;
    							}}catch{ }
    						}
    						num.Add(ne);
    					}}
    				}
    			}
    			s=0;double j=0;
    			for(int h = 0;h<arp.Length/2;h++){
    				try{
    					if(arp[s].ToString()=="-") j-=num[h];
    					else if(arp[s].ToString()=="+") j+=num[h];
    					s+=2;
    				} catch{ }
    			}
    			return $"{j}";
    		}

    如果有绩效,分我一半嘛。

    • 已标记为答案 czhch 2022年3月29日 21:12
    2022年3月29日 7:46