/*
The decimal zip of two non-negative integers A and B is an integer C whose
decimal representation is created from the decimal representations
of A and B as follows:
• the first (i.e. the most significant) digit of C is the first digit of A;
• the second digit of C is the first digit of B;
• the third digit of C is the second digit of A;
• the fourth digit of C is the second digit of B;
• etc.
If one of the integers A and B runs out of digits, the remaining digits of
the other integer are appended to the result.
The decimal representation of 0 is assumed to be "0".
For example, the decimal zip of 12 and 56 is 1526.
The decimal zip of 56 and 12 is 5162.
The decimal zip of 12345 and 678 is 16273845.
The decimal zip of 123 and 67890 is 16273890.
Write a function: function solution(A, B); that, given two non-negative
integers A and B, returns their decimal zip.
The function should return -1 if the result exceeds 100,000,000.
For example, given A = 12345 and B = 678 the function should return
16273845, as explained above.
*/
package com.java.test;
//you can also use imports, for example:
//import java.util.*;
//you can write to stdout for debugging purposes, e.g.
//System.out.println("this is a debug message");
class Solution1 {
public static void main(String[] args){
System.out.println("Input A=12 , B=56 ");
solution(12,56);
System.out.println("Input A=12345 , B=678 ");
solution(12345,678);
System.out.println("Input A=123 , B=67890 ");
solution(123,67890);
}
public static int solution(int A, int B) {
// write your code in Java SE 8
if(A > 100000000 || B > 100000000){
System.out.println("the result exceeds 100,000,000");
return -1;
}
if(A < 0 || B < 0){
System.out.println("A or B is non-negative integer");
return -1;
}
String str_a = String.valueOf(A);
String str_b = String.valueOf(B);
String result = "";
for(int i = 0 ; i < str_a.length() || i < str_b.length(); i++){
if(i < str_a.length()){
result = result + str_a.charAt(i);
}
if(i < str_b.length()){
result = result + str_b.charAt(i);
}
}
System.out.println("Ouput : "+result);
return Integer.parseInt(result);
}
}
/*
*/
總網頁瀏覽量
基礎Note
☪About Me
(1)
免費軟體
(2)
教學
(4)
教學文件
(42)
會計軟體
(1)
電腦系統
(1)
Adapter
(8)
Adobe Premiere
(1)
AlertDialog
(7)
Android App 介紹
(1)
Animation
(1)
API
(2)
APP範例
(1)
Array
(1)
AsyncTask
(1)
Auto Test Case
(32)
AutoCompleteTextView
(1)
Bitmap Drawable
(3)
BroadcastReceiver
(4)
Button
(1)
Codility
(2)
Contact
(4)
DB
(1)
Dialog
(2)
Documents
(1)
Eclipse
(3)
Ellipsize
(1)
File
(4)
Focus
(2)
Fragment
(4)
Gallery
(2)
GIT
(4)
GitHub
(1)
GridView
(8)
HashMap
(1)
HorizontalScrollView
(6)
IIS
(1)
Intent
(3)
IntentService
(1)
Internet
(2)
KeyEvent
(1)
Layout
(1)
ListView
(11)
Log
(1)
Mac / iOS
(11)
Manifest
(1)
Marquee
(2)
Math
(1)
MediaPlayer
(5)
MediaRecorder
(5)
MSMQ
(1)
onClick
(1)
PackageManager
(6)
PHP
(1)
PIS
(3)
PowerManager
(1)
Progress
(2)
SCREEN
(1)
Search
(6)
Service
(1)
SharedPreferences
(3)
SimpleDateFormat
(1)
SonarQube
(1)
Sound Recorder
(1)
Spinner
(2)
SQL server Management
(16)
SQLite
(13)
String
(1)
STS
(5)
SVN
(1)
Thread
(1)
Toast
(3)
Typeface
(1)
Uri
(2)
VB.NET
(17)
VMware
(1)
關於我自己
2016年8月16日 星期二
【Codility】Decimal ZIP problem
訂閱:
張貼留言 (Atom)
To whom It May Concern
回覆刪除DMCA Notification
The following information is presented for the purposes of removing web content that infringes on our copyright per the Digital Millennium Copyright Act. We appreciate your enforcement of copyright law and support of our rights in this matter.
Identification of Copyrighted Work
The copyrighted work at issue is the text that appears on codility.com and its related pages. The pages in question contain a clear copyright notification and are the intellectual property of the complainant.
Identification of Infringed Material
The following copyrighted paragraphs have been allegedly copied from the copyrighted work:
1) Link :
http://bedingfield-tsots.blogspot.com/2016/08/codilitydecimal-zip-problem.html
Text starting from
"The decimal zip of two non-negative integers A and B is an integer C whose"
to
" For example, given A = 12345 and B = 678 the function should return
16273845, as explained above."
Notifying Party
Codility Limited
Attn: Legal Dept.
107 Cheapside
9th Floor
London
EC2V 6DN
United Kingdom
legal@codility.com
Copyright Owners Statement
I have a good faith belief that use of the copyrighted materials described above on the allegedly infringing web pages is not authorized by the copyright owner, its agent, or the law.
I swear, under penalty of perjury, that the information in the notification is accurate and that I am authorized to act on behalf of the copyright owner of an exclusive right that is allegedly infringed.