杭电OJ | 2054 A==B if 判断语句 strchr函数

廉价感情. 提交于 2019-11-27 07:18:25

笔记

1. strchr函数 <string.h>头文件

char *strchr(const char *str, int c)   //str字符串中c字符的第一次出现的位置,如果未找到返回NULL

2. if(条件语句) 

条件语句运算结果不是0则执行if语句块

 

2054

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

Sample Output

NO

#include<stdio.h>
#include<string.h>
void delzero(char a[]);
int main()
{
    char a[100000],b[100000];   //数组要大一些,不然会Runtime Error(ACCESS_VIOLATION)
    while(scanf("%s %s",&a,&b)!=EOF){
    	delzero(a);
    	delzero(b);
		if(strcmp(a,b)==0){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}	
	}
    return 0;
}
//函数功能:如果有小数点并且末尾有0,消除0
void delzero(char a[]){  
	if(strchr(a,'.')){         //判断是否有小数点
		int i = strlen(a)-1;
		while(a[i]=='0'){
			a[i] = '\0';
			i--;
		}
	}
	if(a[strlen(a)-1]=='.'){
		a[strlen(a)-1]='\0';  //将最后一位小数点消除
	}

}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!