Tip to be Palindrome

题目链接:https://ac.nowcoder.com/acm/contest/12794/C

题目描述

One of the cool UCF CS alumni is Dr. Greg, The Palindrome Tipper. A palindrome is a string
that reads the same forward and backward, e.g., madam, abba, 3, 44, 525.
One cool thing about Dr. Greg is that he leaves at least 20% tip when he eats out, e.g., if the meal is 30, Dr. Greg leaves 30, Dr. Greg leaves 6 (30*.20) for tip. If the tip (20%) is not a whole dollar amount, he rounds up the tip to make it a whole number. For example, if the meal is 12, a 20% tip would be12,a202.40 (12*0.20) but Dr. Greg would leave $3 for tip.
Another cool thing about Dr. Greg is that he is a palindrome guru. If his total bill (meal plus tip) is not a palindrome, he will increase the total (by adding to the tip) to make the total a palindrome. He will, of course, add the minimum needed to make the total a palindrome.
The Problem:
Given Dr. Greg’s meal cost, your program should determine the tip amount for him (according to his rules) and the total bill.

输入描述:

The first input line contains a positive integer, n, indicating the number of times Dr. Greg ate out. The meal costs are on the following n input lines, one per line. Each input will contain an integer between 5 and 10000 (inclusive).

输出描述:

At the beginning of each test case, output “Input cost: c” where c is the input cost. Then, on the next output line, print the tip amount and the total bill, separated by one space. Leave a blank line after the output for each test case.

示例1

输入
2
12
84
输出
Input cost: 12
10 22

Input cost: 84
17 101

题目大意:

小费=(消费*0.2),求消费和小费的总和=比消费大的最小回文数。

代码如下:

#include<iostream>
#include<string>
using namespace std;bool judge(int t){int x=0;int y=t;while(t){x=x*10+t%10;t/=10;  }return x==y;
}int main(){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);int cnt = n;if(n%5==0)n+=n/5;elsen+=n/5+1;while(!judge(n)){n++;}printf("Input cost: %d\n%d %d\n",cnt,n-cnt,n);printf("\n");}return 0;
}

2021年度训练联盟热身训练赛第二场 C.Tip to be Palindrome相关推荐

  1. 【2021年度训练联盟热身训练赛第二场】Tip to be Palindrome(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

  2. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

  3. 2021年度训练联盟热身训练赛第五场

    2021年度训练联盟热身训练赛第五场 链接:https://ac.nowcoder.com/acm/contest/13926 A Binary Seating #include<bits/st ...

  4. 2021年度训练联盟热身训练赛第八场

    目录 2021年度训练联盟热身训练赛第八场 A-Fire on Field 题意 思路 代码 B-Gene Tree 题意 思路 代码 I-Thread Knots 题意 思路 代码 J-Triang ...

  5. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  6. 2021年度训练联盟热身训练赛第三场(待补)

    文章目录 前言 一.Circuit Math(后缀表达式---栈&&fgets) 二.Diagonal Cut(gcd最大公因数,数论) 三.expected primary-expr ...

  7. 2021年度训练联盟热身训练赛第二场(全)

    传送门 怎么说呢,这次的训练赛的题目难度不是很大,但就是字多 A Binarize It Professor Boolando can only think in binary, or more sp ...

  8. 2021年度训练联盟热身训练赛第二场(ICPC North Central NA Contest 2019,南阳师范学院),签到题ABCDEFGIJ

    A. Binarize It,简单枚举 链接:https://ac.nowcoder.com/acm/contest/12794/A 来源:牛客网 题目描述 Professor Boolando ca ...

  9. 【2021年度训练联盟热身训练赛第二场】Soccer Standings(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

最新文章

  1. java基础知识-对象和类
  2. Stream流终结操作方法
  3. BATJ一线大公司需要什么样的前端
  4. CREO - 基础3 - 用拉升的方法构建一个双轮胎模型
  5. 【3D游戏建模】3D建模师的发展前景
  6. 支付宝沙箱环境下模拟下单流程
  7. 做好前端的话HTML和CSS基础必须夯实!
  8. jpa入门 ,引自csdn感觉写的很全面
  9. 【python】为本地乌云漏洞库/知识库生成目录
  10. 计算机网络实验5以太网链路帧实验,计算机网络实验-使用Wireshark分析以太网帧与ARP协议.docx...
  11. 知到大学生创业基础(上海理工大学)期末考试试题汇总(含答案)
  12. FSSR : Frequency Separation for Real-World Super-Resolution
  13. windows变量环境
  14. VSCODE 全局搜索失效
  15. 关于传奇皓月GOM引擎登录器配置与生成完整教程
  16. 【Python】Flask学习笔记
  17. “改造” VS Code 编辑器,一起写个插件吧!
  18. GCC 编译器警告——【-Wunused-variable】【-Wunused-parameter】
  19. 加密算法比较:SHA1,SHA256(SHA2),MD5
  20. 电子罗盘在GPS导航设备中的使用

热门文章

  1. (48.1)【WAF绕过-权限控制】webshell、小马、权限脚本、权限工具
  2. Groovy探索之方法调用的动态性
  3. 【阿旭机器学习实战】【11】文本分类实战:利用朴素贝叶斯模型进行邮件分类
  4. 电路理论基础学习笔记(2):chap1 电路元件与电路基本定律
  5. 求方程ax^2+bx+c=0的根(C语言)
  6. 建立SSH隧道(SSH端口转发)
  7. OpenVINO应用案例:部署YOLO模型到边缘计算摄像头
  8. [附下载]史上最简单的深度学习工具“一键式智能AI标注训练平台软件”终于免费公测了,没显卡也可以训练,会点鼠标就可以
  9. windows服务器搭建原神私服教程(附客户端+服务端+环境配置)
  10. 【zmq】REQ REP 模式