PAT甲级2022年冬季考试 20 A-1 Reduction of Proper Fractions

 

考试的时候理解错题意了,觉得是相同的字母都删掉,其实只要相同一个删掉一个;

另外就是所有字母都删完了,剩下个空的"",输出不能是空""要输出0才可以

#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct nod{string val; int num=0;};
int main() {
    string a, c, aa, cc;
    int k, h, y, z, i, j, status0[10], status1[10];
    float res1, res2;
    cin >> a >> c;
    y = stoi(a);
    z = stoi(c);
    res1 = y / (float)z;
    fill(status0, status0+10, 0);  //不能多删也就是一个重复删除一个
    fill(status1, status1+10, 0);  //不能多删也就是一个重复删除一个
    for(i = 0; i < a.length(); i++) { 
        int kk = -9;
        for(j = 0; j < c.length(); j++) {
            if(status1[j]==0 && a[i]==c[j]) {
                status1[j] = 1;
                kk = 9;
                break;
            }
        }
        if(kk < 0) aa += a[i];
    }
    for(i = 0; i < c.length(); i++) {
        int kk = -9;
        for(j = 0; j < a.length(); j++) {
            if(status0[j]==0 && c[i]==a[j]) {
                status0[j] = 1;
                kk = 9;
                break;
            }
        }
        if(kk < 0) cc += c[i];
    }
    if(aa.length()==0) aa="0";
    if(cc.length()==0) cc="0";   //删完以后用0代替
    if(abs(res1- (stoi(aa) / (float)stoi(cc))) < 0.00000001) {
        printf("%d/%d = %d/%d", stoi(a), stoi(c), stoi(aa), stoi(cc));
    }else printf("%d/%d != %d/%d", stoi(a), stoi(c), stoi(aa), stoi(cc));
    return 0;
}

 GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.https://github.com/ZouJiu1/PAT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九是否随机的称呼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值