Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int i,j;
- char a;
- bool o;
- int ip = 1;
- int num[15],gnum[15];
- int numl,nnum,npoint;
- bool number , point , k;
- int s;
- int main() {
- number = false;
- point = true;
- for (i = 1 ; i <= 15 ; i++) {
- if (numl > 0) {
- for (j = 0 ; j < numl ; j++) {
- gnum[j] = num[numl-(j+1)];
- }
- s = gnum[0] + 10 * gnum[1] + 100 * gnum[2] + 1000 * gnum[3];
- if (s > 255) {
- break;
- ip = 0;
- }
- }
- k = false;
- scanf("%c",&a);
- if (a == '.'){
- if (point == false) {
- npoint += 1;
- }
- number = false;
- point = true;
- o = false;
- numl = 0;
- }
- else {
- switch (a) {
- case '0':k = true;
- case '1':k = true;
- case '2':k = true;
- case '3':k = true;
- case '4':k = true;
- case '5':k = true;
- case '6':k = true;
- case '7':k = true;
- case '8':k = true;
- case '9':k = true;
- }
- if (k == false) {
- break;
- if (not (nnum == 4 and npoint == 3))
- ip = 0;
- }
- }
- if (k == true)
- if (number == false and point == true) {
- nnum += 1;
- number = true;
- if (a != '0') {
- o = true;
- numl += 1;
- num[numl-1] = a-'0';
- }
- point = false;
- }
- else {
- point = false;
- if (o == false and a != '0' or o == true) {
- o = true;
- numl += 1;
- num[numl-1] = a-'0';
- }
- }
- }
- if (not (nnum == 4 and npoint == 3))
- ip = 0;
- printf("%i",ip);
- return 0;
- }
Add Comment
Please, Sign In to add comment