Home > Back-end >  Editing the car number
Editing the car number

Time:06-05

On March 9, 2009, Beijing allowed everyone to write your own car motor vehicles with "N" at the beginning of our plate after five,

Editing the car plate rule is as follows: the last of the plate number must be numeric, the remaining four (, and must be at least two to uppercase letters (letters I, O is not available), for example: Beijing NAB999, Beijing NC9D99, Beijing NE99F9, Beijing N9GH99, Beijing N9J9K9, Beijing N99LM9,

Input:
5 the self-made plate

Output:
Whether the plate is compiled in legal
Procedure is as follows:
#include
# define N 5
The main ()
{
Int I, s, x, y, flag.
Char P (N + 1),
The scanf (" % s ", P);
If ((P (N - 1) & gt; '9') | | (P/N - 1] <'0'))
{
flag=0;
}
The else
{
X=0;
y=0;
for(i=0; i<(N - 1); I++)
{
If ((P [I] & gt;='A') & amp; & (P [I] <='Z') & amp; & (P [I]!='I') & amp; & (P [I]! ))
='O'X++;
}

for(i=0; i<(N + 1); I++)
{
If ((P [I] & gt;='0') & amp; & (P [I] <='9'))
Y++;
}
If (x<=4 & amp; & Y<=4 & amp; & X>
=2){
Flag=1;
}
The else
{
flag=0;
}
}
If (flag)
{
Printf (" ok. \ n ");
}
The else
{
Printf (" no. \ n ");
}
}

CodePudding user response:

What's the problem? Also, please the original poster express!

CodePudding user response:

Printf (" % s \ n ", flag?" Ok ":" no ");
The last section of this change,

CodePudding user response:

A judge should be less, x + y is equal to 4

If a lowercase letters or other symbols illegally cases
X + y<4 is illegal input

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include

# define N 5


Int main ()
{

int i;
Char STR [N + 1], CNT=0;

The scanf (" % s ", STR);

If (strlen (STR) & lt; N) {
Printf (" no! \n");
return -1;
}

if (! Isdigit (STR) [N - 1]) {//the last bit must be digit
Printf (" no! \n");
return -1;
}

For (I=0; I & lt; N; I++)
If (isupper (STR [I]) & amp; & STR [I]! & amp;='I' & STR [I]! )
='O'Cnt++;

If (CNT & lt; 2) {
Printf (" no! \n");
return -1;
}

Printf (" ok! \n");


/*
Int I, s, x, y, flag.
Char P (N + 1),
The scanf (" % s ", P);
If ((P (N - 1) & gt; '9') | | (P/N - 1] <'0'))
{
flag=0;
}
The else
{
X=0;
y=0;
for(i=0; i<(N - 1); I++)
{
If ((P [I] & gt;='A') & amp; & (P [I] <='Z') & amp; & (P [I]!='I') & amp; & (P [I]! ))
='O'X++;
}

for(i=0; i<(N + 1); I++)
{
If ((P [I] & gt;='0') & amp; & (P [I] <='9'))
Y++;
}
If (x<=4 & amp; & Y<=4 & amp; & X>
=2){
Flag=1;
}
The else
{
flag=0;
}
}
If (flag)
{
Printf (" ok. \ n ");
}
The else
{
Printf (" no. \ n ");
}
*/
}

For your reference ~

Each limit condition judgment, ~ don't need too complicated

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include

# define N 5


Int main ()
{

int i;
Char STR [N + 1], CNT=0;

The scanf (" % s ", STR);

If (strlen (STR) & lt; N | | strlen (STR) & gt; N) {
Printf (" no! \n");
return -1;
}

if (! Isdigit (STR) [N - 1]) {//the last bit must be digit
Printf (" no! \n");
return -1;
}

For (I=0; I & lt; N; I++)
If (islower (STR [I]) {
Printf (" no! \n");
return -1;
}
If (isupper (STR [I]) & amp; & STR [I]! & amp;='I' & STR [I]! )
='O'Cnt++;

If (CNT & lt; 2) {
Printf (" no! \n");
return -1;
}

Printf (" ok! \n");


}

Further optimize ~
For your reference ~

CodePudding user response:

A little bit more simple:
 
#include

Int main ()
{
Char [b]="ABCDEFGHJKLMNPQRSTUVWXYZ0123456789", n [6], I, j;

For (I=0; I & lt; 6 & amp; & (j=getchar ())!=10) N [i++]=j;
if (i !=5 | | j!=10) puts (" no. ");
The else
{
For (I=j=0; I & lt; 5; N [i++]=j, j=0) while (b [j] & amp; & N [I]!=b [j]) j++;
If (n [4] & gt; 23 & amp; & N [4] <34) for (I=0; I & lt; 4. N [i++] <24? J++ : 0);
J & gt; 1? Puts (" ok ") : puts (" no. ");
}

return 0;
}

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related