• 杭电OJ-2054_A == B ?


    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 76226    Accepted Submission(s): 12101


    Problem Description
    Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
     
    环境:
    第一次在ubuntu下用VSCode编辑,g++编译;

    调了3个小时,到最后都没ac的一题(找不出哪错了)。我写在这记录一下

    1.一开始的时候去掉浮点数的后面的无效0,若小数点后面全是0,则小数点一起去掉(WA)

    2.去掉前导0(WA)

    3.假设前面有符号(WA)

    4.以为数组开小了,改成bank[1000005]。(WA)

    5.崩溃了,过段时间再来看吧。

    代码如下,求大神指导

    #include<iostream>
    using namespace std;
    char bank1[1000005],bank2[1000005];
    int x,y;
    int change(char *bank)
    {
    	bool sign=false;
    	int i;
    	for(i=0;;i++)					//fu dian shu pan duan
    	{
    		if(bank[i]=='')
    			break;
    		else if(bank[i]=='.')
    			sign=true;
    	}
    	if(sign)						//qu chu xiao shu dian hou mian 0
    	{
    		for(int j=i-1;j>=0;j--)
    		{
    			if(bank[j]=='0'||bank[j]=='.')
    				bank[j]='';
    			else
    				break;
    		}
    	}
    	int a=0;
    	for(int i=0;;i++)					//qu chu qian dao 0 he + -
    	{
    		if(bank[i]=='0'||bank[i]=='+'||bank[i]=='-')
    		 a++;
    		 else
    		 break;
    	}
    	//cout<<a<<endl;
    	return a;
    }
    
    
    int main()
    {
    	while(cin>>bank1>>bank2)
    	{
    			bool sign=true,sign1=false;
    			x=change(bank1);
    			y=change(bank2);
    			//cout<<bank1<<endl;
    			//cout<<bank2<<endl;		
    			for(int i=x,j=y;;i++,j++)
    			{
    				if(bank1[i]=='')
    				{
    					if(bank2[i]!='')
    						sign=false;
    					break;
    				}
    				if(bank1[i]!=bank2[j])
    				{
    					//cout<<"12:"<<bank1[i]<<bank2[i]<<endl;
    					sign=false;
    				}	
    			}
    			//cout<<sign<<endl;
    			if(bank1[0]==bank2[0])
    				sign1=true;
    			else if(bank1[0]=='+'&&bank2[0]>='0'&&bank2[0]<='9') 
    				sign1=true;
    			else if(bank2[0]=='+'&&bank1[0]>='0'&&bank2[0]<='9')
    				sign1=true;
    			cout<<(sign&&sign1?"YES":"NO")<<endl;
    	}
    }




  • 相关阅读:
    HDFS命令操作和高可用
    nginx-nginx和反向代理概念
    day01 Hadoop 简单介绍及架构设计
    常用正则表达式
    【JavaWeb笔记】第二章 JDBC
    【JavaSE笔记】第二章 进制数据类型和运算符
    LeetCode-94 Binary Tree Inorder Traversal Solution (with Java)
    LeetCode-1019 Next Greater Node In Linked List Solution (with Java)
    LeetCode-946 Validate Stack Sequences Solution (with Java)
    LeetCode-739 Daily Temperatures Solution (with Java)
  • 原文地址:https://www.cnblogs.com/A-yes/p/9894243.html
Copyright © 2020-2023  润新知