自己做这道题第一次用到了strchr这个函数;
strchr函数原型:extern char *strchr(const char *s,char c);查找
字符串s中首次出现字符c的
位置。
A == B ?Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 61130 Accepted Submission(s): 9517
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
AC代码:
#include<stdio.h>
#include<string.h> #define M 1000000 char s[M]; char p[M]; int fun(char *p) { int n,i,j; n=strlen(p); if(strchr(p,'.')!=NULL) { for(i=n-1;p[i]=='0';i--); if(p[i]=='.') p[i]='\0'; else p[i+1]='\0'; } for(i=0;p[i]=='0'&&p[i+1]!='\0';i++); return i; } int main() { while(~scanf("%s %s",s,p)) { int m,k,t; int i,j; for(i=fun(s),j=fun(p);s[i]!='\0'&&p[j]!='\0';i++,j++) { if(s[i]!=p[j]) { //printf("NO\n"); break; } } if(s[i]=='\0'&&p[j]=='\0') printf("YES\n"); else printf("NO\n"); } return 0; } |