当前位置: 首页 > news >正文

PAT乙题1011

答案

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int ll;
int main()
{int n,cnt=1;cin >> n;while (n--){ll a, b, c; cin >> a >> b >> c;printf("Case #%d: ", cnt);a + b > c ? puts("true") : puts("false");cnt++;}return 0;
}

注意:

typedef

puts("   ")输出字符串

自己写的:

我知道了vector数组是可以直接比较大小的

但是这个程序比较不了负数,不知道咋办

#include <iostream>
#include<cstdio>
#include<vector>
using namespace std;vector<int> add(vector<int> A, vector<int> B)
{vector<int> D;int t = 0;for (int i = 0; i < A.size()||i<B.size(); i++){if (i < A.size())t += A[i];if (i < B.size()) t += B[i];D.push_back(t % 10);t /= 10;}if (t) D.push_back(t);return D;
}
/*bool compare(vector<int> m, vector<int> n)
{if (m.size() == n.size()){for (int i = m.size() - 1; i >= 0; i--){if (m[i] > n[i])return true;}return false;}else {if (m.size() > n.size())return true;else return false;}
}*/
int main()
{int n,cnt=1;cin >> n;while (n--){string a, b, c;cin >> a >> b >> c;vector<int> A, B, C;for (int i = a.length() - 1; i >= 0; i--) A.push_back(a[i] - '0');for (int i = b.length() - 1; i >= 0; i--) B.push_back(b[i] - '0');for (int i = c.length() - 1; i >= 0; i--) C.push_back(c[i] - '0');vector<int> ans = add(A, B);if (ans>C){cout << "Case #" << cnt << ": true" << endl;}else{cout << "Case #" << cnt << ": false" << endl;}cnt++;}return 0;
}

注意:

string用.length()

vector动态数组用.size()

http://www.lryc.cn/news/111460.html

相关文章:

  • 【并发专题】单例模式的线程安全(进阶理解篇)
  • 无涯教程-Perl - if...elsif...else语句函数
  • uniapp 实现滑动元素并下方有滚动条显示
  • QT充当客户端模拟浏览器等第三方客户端对https进行双向验证
  • 【JVM】 垃圾回收篇——自问自答(1)
  • Image Line FL Studio v21.0.3.3517 Producer版全插件版WIN免费下载完整版
  • PHP8条件控制语句-PHP8知识详解
  • 【PHP代码审计】ctfshow web入门 php特性 93-104
  • CSS元素的显示模式
  • Go strings.Title方法被废弃(Deprecated)
  • vuejs源码分析之全局API(vm.$off)
  • elasticSearch常见的面试题
  • 第一课-前提-Stable Diffusion 教程
  • Python 开发工具 Pycharm —— 使用技巧Lv.2
  • 代码随想录第39天 | 62. 不同路径、63.不同路径II
  • QMT入门—初识QMT
  • C 语言的 return 语句
  • 企业级Vue路由角色权限应该怎么做?
  • 3.2.0 版本预告!Apache DolphinScheduler API 增强相关功能
  • 测试工程师的工作
  • 压力测试与测试工具jmeter的介绍
  • 解析整型最大值(Integer.MIN_VALUE)溢出变为最小值(Integer.MAX_VALUE)
  • 【openpcdet】dbinfo内的信息
  • clickhouse查询缓存
  • vue中使用Base64加密、解密以及des加密、解密
  • 关于丢失安卓秘钥的撞sha-1值的办法
  • maven如何打包你会吗?
  • idea 控制台 打印 Tomcat日志Tomcat Catalina Log控制台乱码问题
  • python我的世界
  • SpringBoot+vue 大文件分片下载