解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class A1116 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
loop: do {
String s = sc.next();
int n = 0;
char a[] = new char[s.length()];
for (int i = 0; i < a.length; i++) {
a[i] = s.charAt(i);
}
int b = 0;
int c = 0;
for (int i = 0; i < a.length; i++) {
int sum = 0;
if (a[i] == '.') {
c = i;
for (int x = b; x < c; x++) {
if (a[x] == '.') {
continue;
}
if (a[x] >= '0' && a[x] <= '9') {
sum = sum * 10 + a[x]-48;
} else {
System.out.println("N");
continue loop;
}
}
b = c;
}
if(a[i]!='.')
continue;
if (sum <= 255) {
n++;
}
if (sum >= 255) {
System.out.println("N");
continue loop;
}
if (n == 3) {
sum = 0;
for (int x = c; x < a.length; x++) {
if (a[x] == '.') {
continue;
}
if (a[x] >= '0' && a[x] <= '9') {
sum = sum * 10 + a[x]-48;
} else {
System.out.println("N");
continue loop;
}
}
if (sum <= 255)
System.out.println("Y");
if (sum >= 255) {
System.out.println("N");
continue loop;
}
}
}
} while (sc.hasNext());
}
}
0.0分
0 人评分
简单的a+b (C语言代码)浏览:564 |
C语言训练-求PI* (C语言代码)浏览:638 |
A+B for Input-Output Practice (V) (C语言代码)浏览:497 |
大家好,我是验题君浏览:604 |
1128题解(返回值为数组的情况)浏览:571 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:692 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:441 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:469 |
C语言训练-百钱百鸡问题 (C语言代码)浏览:541 |
C二级辅导-统计字符 (C语言描述——用函数求解)浏览:1229 |