HDU ACM 2054 A == B ? 水题

分析:水题,主要是要注意几个细节。

#include<iostream>
using namespace std;

char a[100005],A[100005];
char b[100005],B[100005];

void Process(char* p,int count,char* p2)
{
	int pos;
	bool is_real;
	int i=0,k=0,j;

label:
	while(*(p+i)!='\0' && *(p+i)=='0')
		i++;
	if(*(p+i)=='\0')
	{
		p2[0]='0',p2[1]='\0';
		return ;  //为0
	}

	if(*(p+i)=='-')
	{
		p2[k++]='-';
		i++;
		goto label;
	}

	if(*(p+i)=='+')
	{
		i++;     //处理正数
		goto label;
	}

	while(*(p+i)!='\0' && *(p+i)!='.') p2[k++]=p[i],i++;

	if(*(p+i)=='\0')
	{
		p2[k]='\0';
		return ;
	}

	is_real=false;
	for(j=count-1;j>i;j--)
		if(is_real || p[j]!='0')
		{
			if(!is_real) pos=j;
			p2[k+j-i]=p[j];
			is_real=true;
		}

	if(!is_real)
		p2[k]='\0';
	else
		p2[k]='.',p2[k+pos-i+1]='\0';
}

bool IsEqual()
{
	Process(a,strlen(a),A);
	Process(b,strlen(b),B);

	if(!strcmp(A,B)) return true;
	else return false;
}

int main()
{
	while(scanf("%s %s",a,b)==2)
	{
		if(IsEqual()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
时间: 2024-10-12 23:16:49

HDU ACM 2054 A == B ? 水题的相关文章

HDU ACM 2521 反素数 水题+因子打表

分析:水题,不解释. #include<iostream> using namespace std; int cnt[6000]; void init() //打表 { int i,j; memset(cnt,0,sizeof(cnt)); cnt[1]=1; //1只有他本身 for(i=2;i<=5005;i++) { cnt[i]+=2; //1和他本身 for(j=2;j<=i/2;j++) if(i%j==0) cnt[i]++; } } int main() { int

HDU ACM 1031 Design T-Shirt 水题

分析:给你n个人M件衣服, 选出前K件衣服评价最大值,注意要输出的是编号,编号从大到小.两次排序即可. #include<iostream> #include<algorithm> using namespace std; struct node { double m; int id; }; bool cmp(const node& a,const node& b) { if(a.m!=b.m) return a.m>b.m; else return a.id

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ

HDU 5578 Friendship of Frog 水题

Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee

杭电(hdu)2070 Fibbonacci Number 水题

Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17675    Accepted Submission(s): 8422 Problem Description Your objective for this question is to develop a program which will g

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o