1023. Have Fun with Numbers (20)
生词以及在文中意思
duplication 重复 permutation 排列 property 属性
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String s=sc.next();
int [] a=new int[s.length()];
for(int i=0;i<s.length();i++) {
a[i]=s.charAt(i)-48;
}
boolean IsTrue=true;
int sum=0;
int [] cnt1=new int[21];
int [] cnt2=new int[21];
int [] result=new int[21];
for(int i=s.length()-1;i>=0;i--) {
int n=s.charAt(i)-48;
cnt1[n]++;
n=2*n+sum;
int m=n%10;
sum=n/10;
result[i]=m;
cnt2[m]++;
}
if(sum!=0) {//如果有进位,把它放在result数组的[s.length()]位置上
IsTrue=false;
result[s.length()]=sum;
cnt2[sum]++;
}
int sum1=0;
int sum2=0;
for(int i=0;i<21;i++) {
if(cnt1[i]!=cnt2[i]) {
IsTrue=false;
}
}
if(IsTrue) {
System.out.println("Yes");
}
else {
System.out.println("No");
}
if(sum==0) {
for(int i=0;i<s.length();i++) {
System.out.print(result[i]);
}
}
else {//如果有进位,先输出放在后面的进位数字
System.out.print(result[s.length()]);
for(int i=0;i<s.length();i++) {
System.out.print(result[i]);
}
}
}
}
1023. Have Fun with Numbers (20)的更多相关文章
- PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- 1023 Have Fun with Numbers (20 分)
1023 Have Fun with Numbers (20 分) Notice that the number 123456789 is a 9-digit number consisting ...
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
- 1023 Have Fun with Numbers (20)(20 point(s))
problem Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 t ...
- PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]
题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...
- PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法
和1024一样都是大数据的题,因为位数最多要20位,long long最多19位给一个num,求sum=num+num问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了. #i ...
- 【PAT甲级】1023 Have Fun with Numbers (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- PAT (Advanced Level) 1023. Have Fun with Numbers (20)
手动模拟一下高精度加法. #include<iostream> #include<cstring> #include<cmath> #include<algo ...
- PAT 1023 Have Fun with Numbers[大数乘法][一般]
1023 Have Fun with Numbers (20)(20 分) Notice that the number 123456789 is a 9-digit number consistin ...
随机推荐
- threejs 草场足球运动视角(三)
这次要模拟的场景如下图:就是在绿草地上足球的运动,并且视角会随着足球的运动发生变化,同时整个草地的视角也会旋转. 接下来,我们就对各个元素进行分析: 1,草地 用PlaneGeometry在三维空间里 ...
- js 空语句
不写就行了 ){}
- springboot自定义starter
1,创建一个空工程 2,new一个Modules ---------------- maven (启动器) : springboottest-spring-boot-starter 3,new一个M ...
- Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ElasticsearchParseException[malformed, expected end of settings but encountered additional conte
D:\elasticsearch\elasticsearch-2.4.0\bin>elasticsearchException in thread "main" Settin ...
- Python 进度条原理
#进度条原理 import sys,time for i in range(50): sys.stdout.write("#")#标准输出 #若不能够按照时间一个一个依次显示,则代 ...
- @mentions for Users with ActionText; 使用Tribute.js库
git clone从https://github.com/chentianwei411/at-mentions-with-action-text 先fork下来,然后拷贝https连接,最后在term ...
- Python turtle学习笔记
1介绍 Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而 ...
- bilinear pooling
一.双线性汇合的计算过程: 第一步,计算Gram 矩阵: 对于一组H×W×D的feature maps,$\boldsymbol{x}_{i} \in \mathbb{R}^{D}$是图像的深度描述, ...
- 多组图自动无限循环(swiper轮播)
前两天的一个项目中遇到多组图片无限轮播,当时采用了swiper 但是没有解决让它无限轮播.今天再次尝试了一下发现是自己的样式写错了.今天在这里写一下,为了给自己一个警醒不要犯同样的错误 首先先引入一下 ...
- 序列化---Serializable与Externalizable源码
Serializable接口总结: 1. java.io.Serializable接口是一个标识接口,它没有任何字段和方法,用来表示此类可序列化: 2. 父类声明该接口,则其与其所有子类均可序列化,都 ...