miaozhiqiang / samething Goto Github PK
View Code? Open in Web Editor NEWいろいろなもの
いろいろなもの
import java.io.IOException;
import java.util.regex.Pattern;
public class Main {
/**
* 11,12桁半角数字
*/
private static final String CHECK_REGEX = "[0-9]{11,12}";
public static void main( String[] args ) throws IOException {
int c;
StringBuilder input = new StringBuilder();
while ( ( c = System.in.read() ) != -1 ) {
if ( c == 10 ) {
checkMyNmber( input.toString() );
input = new StringBuilder();
continue;
}
input.append( (char) c );
}
}
private static void checkMyNmber( String myNmber ) {
if ( !Pattern.matches( CHECK_REGEX, myNmber ) ) {
System.out.println( "Error" );
return;
}
String checkDigit = calcDigit( myNmber.substring( 0, 11 ) );
if ( myNmber.length() == 11 ) {
System.out.println( checkDigit );
} else {
if ( checkDigit.equals( myNmber.substring( 11, 12 ) ) ) {
System.out.println( "OK" );
} else {
System.out.println( "NG" );
}
}
}
private static String calcDigit( String number ) {
int sum = 0;
for ( int i = 1; i <= 11; i++ ) {
int pn = Integer.valueOf( number.substring( 11 - i, 12 - i ) );
int qn = i <= 6 ? i + 1 : i - 5;
sum += pn * qn;
}
int mod = sum % 11;
if ( mod <= 1 ) {
return "0";
} else {
return String.valueOf( 11 - mod );
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.