2020 Object-Oriented Programming 1 winter operations program title

Programming questions
Chinese culture is profound, starting from Changjei creation, Chinese characters has been passed down to this day. When we lamented the long history of Chinese characters, but also can not help feeling, why not a programming language using Chinese characters?
Chinese characters can not really programming? Recently classical programming a fire, I have a number. Said III. Name, called "armor." This unpretentious variable definition is certainly not thousands of years of Chinese culture in the development of a wonderful work.
Today, Wang students think, classical vernacular that can be programmed to do? He found you, let you help him.
Programming requires
the preparation of a program, the result of input to meet the following syntax requirements of a piece of text output operation.
Variable Definition: an integer equal to zero wallet
arithmetic (adder): Purse increased by 4
operation (subtraction): Purse reduced by four
outputs: a look wallet
Sample
input:
an integer equal to zero wallet
purse increased by 4
wallet decrease three
look wallet
output:
a

Ideas: Taking into account only the 0-99 range of data, so the data is divided into multiple 0-10,10, and 11-19, and the remaining number four parts sequentially Chinese and Arabic digital conversion
complete code:
Due to lack of capacity, at the beginning only the number of 0-10 converts

include<stdio.h>

include<string.h>

int num(char n[])
{
if(strcmp(n,"零")==0) return 0;
else if(strcmp(n,"一")==0) return 1;
else if(strcmp(n,"二")==0) return 2;
else if(strcmp(n,"三")==0) return 3;
else if(strcmp(n,"四")==0) return 4;
else if(strcmp(n,"五")==0) return 5;
else if(strcmp(n,"六")==0) return 6;
else if(strcmp(n,"七")==0) return 7;
else if(strcmp(n,"八")==0) return 8;
else if(strcmp(n,"九")==0) return 9;
else if(strcmp(n,"十")==0) return 10;
else return -1;
}
void chinese(int a)
{
switch(a)
{
case 0:printf("零");break;
case 1:printf("一");break;
case 2:printf("二");break;
case 3:printf("三");break;
case 4:printf("四");break;
case 5:printf("五");break;
case 6:printf("六");break;
case 7:printf("七");break;
case 8:printf("八");break;
case 9:printf("九");break;
case 10:printf("十");break;
}
}
int main()
{
char z[100],q[100],d[100],n[100];
int a;
scanf("%s %s %s %s",z,q,d,n);
getchar();
if(strcmp(z,"整数")==0)//z为整数
{
if(strlen(n)==2)
{
a=num(n);
if(a!=-1)
{
for(int i=0;i<2;i++)
{
char b[10],c[10],d[10];
scanf("%s %s %s\n",b,c,d);
if(strcmp(c,"增加")==0) a+=num(d);
if(strcmp(c,"减少")==0) a-=num(d);
}
scanf("看看 钱包");
}
chinese(a);//printf("%d",a);
}
}
else printf("Error");
return 0;
}

And modify the code, will expand the range of data, but the output is still a problem, there is no thinking results, we also hope the exhibitions.

include<stdio.h>

include<string.h>

int num(char n[])
{
if(strcmp(n,"零")==0) return 0;
else if(strcmp(n,"一")==0) return 1;
else if(strcmp(n,"二")==0) return 2;
else if(strcmp(n,"三")==0) return 3;
else if(strcmp(n,"四")==0) return 4;
else if(strcmp(n,"五")==0) return 5;
else if(strcmp(n,"六")==0) return 6;
else if(strcmp(n,"七")==0) return 7;
else if(strcmp(n,"八")==0) return 8;
else if(strcmp(n,"九")==0) return 9;
else if(strcmp(n,"十")==0) return 10;
else return -1;
}
void chinese(int a)
{
switch(a)
{
case 0:printf("零");break;
case 1:printf("一");break;
case 2:printf("二");break;
case 3:printf("三");break;
case 4:printf("四");break;
case 5:printf("五");break;
case 6:printf("六");break;
case 7:printf("七");break;
case 8:printf("八");break;
case 9:printf("九");break;
case 10:printf("十");break;
}
}
int main()
{
char z[100],q[100],d[100],n[100];
int a;
scanf("%s %s %s %s",z,q,d,n);
getchar();
if(strcmp(z,"整数")==0)//z为整数
{
if(strlen(n)==2)//处理0-10
{
a=num(n);
if(a!=-1)
{
for(int i=0;i<2;i++)
{
char b[10],c[10],d[10];
scanf("%s %s %s\n",b,c,d);
if(strcmp(c,"增加")==0) a+=num(d);
if (strcmp (c, "reduce") == 0) = NUM A- (D);
}
Scanf ( "See wallet");
}
chinese (A); // the printf ( "% D", A);
}
the else IF (strlen (n-) ==. 3) // process a multiple of 10, 11-19
{
char AA [10], BB [10];
AA [0] = n-[0]; BB [0] = n- [1];
a multiple of 10 // if (bb [0] == 'ten')
{
a = NUM (AA) * 10;
IF (a> = 0)
{
for (int I = 0; I <2; I ++)
{
char B [10], C [10], D [10];
Scanf ( "% S% S% S \ n-', B, C, D);
IF (strcmp (C," increase ") = = 0) A + = NUM (D);
IF (strcmp (C, "reduce") == 0) A- = NUM (D);
}
Scanf ( "See wallet");
}
IF (A> = 0 && A < 10 =) chinese (A);
the else IF (A> 10 && A <20)
{
printf("十");
chinese(a%10);
}
else if(a==20&&a==30&&a==40&&a==50&&a==60&&a==70&&a==80&&a==90)
{
chinese(a/10);
printf("十");
}
else
{
chinese(a/10);
printf("十");
chinese(a%10);
}
}
else if(aa[0]=='十')//11-19
{
a=10+num(bb);
if(a>=0)
{
for(int i=0;i<2;i++)
{
char b[10],c[10],d[10];
scanf("%s %s %s\n",b,c,d);
if(strcmp(c,"增加")==0) a+=num(d);
if(strcmp(c,"减少")==0) a-=num(d);
}
scanf("看看 钱包");
}
if(a>=0&&a<=10) chinese(a);
else if(a>10&&a<20)
{
printf("十");
chinese(a%10);
}
else if(a==20&&a==30&&a==40&&a==50&&a==60&&a==70&&a==80&&a==90)
{
chinese(a/10);
printf("十");
}
else
{
chinese(a/10);
printf("十");
chinese(a%10);
}
}
}
}
return 0;
}

Guess you like

Origin www.cnblogs.com/jasf/p/12231679.html
Recommended