zoukankan      html  css  js  c++  java
  • A == B ?(思维)

    A == B ?

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


    Problem Description
    Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
     
    Input
    each test case contains two numbers A and B.
     
    Output
    for each case, if A is equal to B, you should print "YES", or print "NO".
     
    Sample Input
    
    
    1 2 2 2 3 3 4 3
     
    Sample Output
    
    
    NO YES YES NO
     
    Author
    8600 && xhd

    思路:把小数点后面的多余的零去掉,同时注意如果最后一位是小数点的话,也要去掉,(就在这里wa了好多次)

    上代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn = 1e6+5;
    char a[maxn],b[maxn];
    int qSpot(char *c,int lenn){
    	int len = lenn,len1 = lenn;
    	for(int i = 0;i<len;i++){
    		if(c[i]=='.'){
    			len = i;
    			break;
    		}
    	}
    	int s = 0;
    	for(int i = len1-1;i>=len;i--){
    		if(c[i]=='0'){
    			s++;
    		}
    		else{
    			break;
    		}
    	}
    	if(c[len1-s-1] == '.') s++;
    	return len1 - s;
    }
    int main()
    {
    	while(~scanf("%s %s",a,b)){
    		int len = strlen(a);
    		int len1 = strlen(b);
    		len = qSpot(a,len);
    		len1 = qSpot(b,len1);
    		//printf("%d %d
    ",len,len1);
    		if(len != len1) printf("NO
    ");
    		else{
    			bool falg = true;
    			for(int i = 0;i<len;i++){
    				if(a[i]!=b[i]){
    					falg = false;
    				}
    				if(falg == false) break;
    			}
    			if(falg) printf("YES
    ");
    			else printf("NO
    ");
    		}
    	}
    	return 0;
     } 


  • 相关阅读:
    ubutu安装phonegap 后出现/usr/bin/env:node No such file or directory的错误
    Ubuntu 14.04 x64 安装 Android SDK
    ubuntu64安装ia32-libs
    redis 配置
    flask部署阿里云
    爬虫数据存储
    selnuim 使用
    python 爬虫解析_1_
    scrapy 数据存储mysql
    scrapy 小案例
  • 原文地址:https://www.cnblogs.com/Nlifea/p/11746047.html
Copyright © 2011-2022 走看看