Reversion Count
字符串基础用法题,包含有大数减法大数除法模板,不难理解,代码如下:
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
string a,b,c;
string sub(string a, string b)
{
string c;
bool ok = ;
int len1 = a.length();
int len2 = b.length();
int len = max(len1, len2);
for(int i = len1; i < len; i++)//短的串前边加0方便后边计算
a = "" + a;
for(int i = len2; i < len; i++)
b = "" + b;
if(a < b)//判断正负
{
string temp = a;
a = b;
b = temp;
ok = ;
}
for(int i = len - ; i >= ; i--)
{
if(a[i] < b[i])
{
a[i - ] -= ;
a[i] += ;
}
char temp = a[i] - b[i] + '';
c = temp + c;//此处不能写为c+temp因为是倒着算,需要正着存,顺序写错就不对了,自己可以试几组样例
}
int pos = ;
while(c[pos] == '' && pos < len) pos++;//去除前导0
if(pos == len) return "";
if(ok) return "-" + c.substr(pos);
return c.substr(pos);
} string chufa(string s,int x)
{
int jj=,fla=;
string ans="";
for(int i=; i<s.size(); i++)
{
jj=jj*+s[i]-'';
if(jj>=x)
{
fla=;
ans+=jj/x+'';
jj%=x;
}
else
{
if(fla==)//在运算过程中不够除商0;
ans+='';
}
}
return ans;
}
int main()
{
int n,i,j;
while(cin>>a)
{
set<char>qq;
b=a;
reverse(a.begin(),a.end());
c=sub(b,a);
if(c[]=='-')//题目不要求正负,可以删除再计算
c.erase(,);
if(c.size()==)
{
printf("YES\n");
continue;
}
string ans=chufa(c,); for(int i=; i<ans.size(); i++)
{
qq.insert(ans[i]);
}
if(qq.size()==)
printf("YES\n");
else
printf("NO\n");
}
}
Reversion Count的更多相关文章
- 2018宁夏邀请赛网赛 I. Reversion Count(java练习题)
题目链接 :https://nanti.jisuanke.com/t/26217 Description: There is a positive integer X, X's reversion c ...
- 计蒜客——Reversion Count
Reversion Count 解析:题目数字的长度最大为 99,因此使用字符串处理,那么必然这些数存在某些规律.对于数 a (XYZW) 和数 b (WZYX),原式 = (1000X + 100Y ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 I. Reversion Count (java大数)
Description: There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1 ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛暨丝绸之路程序设计竞赛
三道大水题,其它题都不会做,真是尴尬和无奈啊…… 有想法,但是解决不了,感觉个人不会一些基本解法,终究还是个人学习的内容太少了 B. Goldbach /* 数值较小,<2^63,分解的两个素数 ...
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
- [PHP源码阅读]count函数
在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...
- EntityFramework.Extended 实现 update count+=1
在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...
- 学习笔记 MYSQL报错注入(count()、rand()、group by)
首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...
随机推荐
- 计算概论(A)/基础编程练习(数据成分)/1:短信计费
#include<stdio.h> int main() { // 输入当月发送短信的总次数n和每次短信的字数words int n,words; scanf("%d" ...
- window JNI_CreateJavaVM启动java程序
https://blog.csdn.net/earbao/article/details/51889605 #define _CRT_SECURE_NO_WARNINGS 1 #inclu ...
- 算法笔记 #007# Backtracking
留着备用. 题目描述和代码参考:https://www.geeksforgeeks.org/8-queen-problem/ NQueenProblem(js代码): class NQueenProb ...
- PyCharm配置MySQL
有时候电脑没有安装Navicat,也想要操作数据库,那么PyCharm也能实现Navicat的一些功能.下面演示,用PyCharm如何连接数据库并执行操作: 1. 打开PyCharm,在右侧边栏打开D ...
- shell脚本一键安装redis集群[最终版]
直接上shell了. #!/bin/bash #---------------------------------------------------------------------------- ...
- 集合框架-Map集合
* Map集合和Collection集合的区别? * Map集合存储元素是成对出现的,Map集合的键是唯一的,值是可重复的.可以把这个理解为:夫妻对 * Collection集合存储元素是单独出现的, ...
- 基于快速排序思想partition查找第K大的数或者第K小的数。
快速排序 下面是之前实现过的快速排序的代码. function quickSort(a,left,right){ if(left==right)return; let key=partition(a, ...
- Bootstrap3基础 btn-primary/warning... 三类按钮的六种样式
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- kubeadm 生成的token过期后,集群增加节点
通过kubeadm初始化后,都会提供node加入的token: You should now deploy a pod network to the cluster. Run "kubect ...
- (转)Spring Boot(二) & lombok
(二期)5.springboot框架集成与lombok [课程五]springb...mbok.xmind0.1MB [课程五预习]spr...mbok.xmind0.1MB springboot的版 ...