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 ...
随机推荐
- ArcGIS Pro开发Web3D应用(1)——环境搭建与初始实例
1.搭建环境 1.1 ArcGIS Web3D软件环境 ArcGIS Pro 2.0(必须) ArcGIS for Enterprise 10.5.1 (从10.5开始称呼为Enterprise)包括 ...
- 雷林鹏分享:jQuery EasyUI 数据网格 - 自定义排序
jQuery EasyUI 数据网格 - 自定义排序 如果默认的排序行为不满足您的需求,您可以自定义数据网格(datagrid)的排序行为. 最基础的,用户可以在列上定义一个排序函数,函数名是 sor ...
- 持续集成CI/CD
Gitlab+kubernetes+docker+jenkins+harbor搭建持续交付系统 http://blog.chenmiao.cf/2016/12/28/gitlab+kubernetes ...
- python两个列表合并为字典,一个作为key,一个作为value
两个列表合并为一个字典函数list_dic(list1,list2)可以直接复制拿走 传入的参数为两个列表,list1准备作为key,list2准备作为value,key和value位置一一对应. d ...
- Python --判断路径是否为目录或文件
os.path.isdir( ), os.path.isfile(),os.listdir( ), os.walk( ) 参考网址:https://blog.csdn.net/xxn_723911/a ...
- mysql5.7.25安装
附:mysql安装包 链接:https://pan.baidu.com/s/1vROdBSw0GiMWCRpuwmqFCg 提取码:ug4o a.运行mysql-installer-community ...
- Word中如何删除目录页的页码
---恢复内容开始--- word中插入目录之后想要为每页添加页码,如果我们直接添加页码的话会出现目录是第一页,正文部分的页码是从2开始而不是1,用下面的方法就可以解决 首先让文档中的所有符号可见 第 ...
- Monkey
什么是 Monkey Monkey 是一个 Android 自动化测试小工具.主要用于Android 的压力测试, 主要目的就是为了测试app 是否会Crash. Monkey 特点 顾名思义,Mon ...
- SQL Join 与 In的效率
今天在优化朋友的一个系统, 主要他们前期是叫人外包写的, 越来越慢, 导出订单明细时, 基本都是TimeOut, 我查看到这里面是这样写: select * from Orders where ID ...
- 3ci