【玲珑学院OJ1065】Just for Fun(模拟)

来源:互联网 发布:传奇引擎全套源码 编辑:程序博客网 时间:2024/06/04 18:33

记录一个菜逼的成长。。

这里写图片描述
题目链接
对于这题。。我也是服的。
迷之题意。
输入并没有说是整数。wa了几发。
后来用double 又wa了几发。。
没想到爆了double 的精度。
就只能用字符串。
然而输入会有前导0
纯粹变成一道模拟题了。
写起来会有点烦。
写下我的判断顺序,理解了就好。
显然n == 1 或者 p == 0是正解
先判断是否有小数点。
如果有再判断小数点后是不是都是0。
对于n : 再去掉前导0 ,最后判断小数点前面是不是只有一个数 并且这个数是1
对于p : 再判断小数点前面是不是都是0
如果没有小数点
对于n : 只要判断去掉前导0后是不是为1
对于p : 只要判断是不是全是0

//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cstdlib>#include <vector>#include <set>#include <map>#include <queue>#include <stack>#include <list>#include <deque>#include <cctype>#include <bitset>#include <cmath>#include <cassert>using namespace std;#define ALL(v) (v).begin(),(v).end()#define cl(a,b) memset(a,b,sizeof(a))#define bp __builtin_popcount#define pb push_back#define mp make_pair#define fin freopen("D://in.txt","r",stdin)#define fout freopen("D://out.txt","w",stdout)#define lson t<<1,l,mid#define rson t<<1|1,mid+1,r#define seglen (node[t].r-node[t].l+1)#define pi 3.1415926#define exp  2.718281828459#define lowbit(x) (x)&(-x)typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII;typedef pair<LL,LL> PLL;typedef vector<PII> VPII;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;template <typename T>inline void read(T &x){    T ans=0;    char last=' ',ch=getchar();    while(ch<'0' || ch>'9')last=ch,ch=getchar();    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();    if(last=='-')ans=-ans;    x = ans;}const int maxn = 5000000 + 10;char n[maxn],p[maxn];int main(){    int T;    scanf("%d",&T);    while(T--){        scanf("%s%s",n,p);        int ln = strlen(n),lp = strlen(p);        int i = 0,dian = 0;        while(n[i] != '.' && n[i] != '\0')i++;        if(n[i] == '.'){            dian = i;            int flag = 1;            for( i += 1; n[i] != '\0'; i++ ){                if(n[i] != '0'){                    flag =0;                    break;                }            }            if(flag){                i = 0;                while(n[i] != '.' && n[i] == '0')i++;                if(n[i] != '.' && i + 1 == dian && n[i] == '1'){                    puts("Y");                    continue;                }            }        }        else {            i = 0;            while(n[i] == '0')i++;            if(i + 1 == ln && n[i] == '1'){                puts("Y");                continue;            }        }        i = 0;        dian = 0;        while(p[i] != '.' && p[i] != '\0')i++;        if(p[i] == '.'){            dian = i;            int flag = 1;            for( i += 1; p[i] != '\0'; i++ ){                if(p[i] != '0'){                    flag = 0;                    break;                }            }            if(flag){                for( int j = 0; j < dian; j++ ){                    if(p[j] != '0'){                        flag = 0;                        break;                    }                }                if(flag){                    puts("Y");                    continue;                }            }        }        else {            int flag = 1;            for( int j = 0; p[j] != '\0'; j++ ){                if(p[j] != '0'){                    flag = 0;                    break;                }            }            if(flag){                puts("Y");                continue;            }        }        puts("N");    }    return 0;}
0 0
原创粉丝点击