第一次个人编程作业·寒假

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/SE/
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/SE/homework/10283
这个作业的目标 制作一个简易的中文语言编译器
作业正文
其他参考文献

1.编程题目
汉字是迄今为止持续使用时间最长的文字,也是上古时期各大文字体系中唯一传承至今者,中国历代皆以汉字为主要的官方文字。我们在感叹汉字的源远流长时,也不禁感慨,为什么没有一门使用汉字编程的语言?
小杨同学想到:用汉字来进行编程一定很有趣,来请你帮帮他。

2.编程要求
请编写一个程序,制作一个简易的中文语言编译器,即使用中文语法进行编程,输入为逐行输入,每行为一个语句,一个语句代变一个操作,满足以下语法要求(括号内代变格式类型,具体参考样例):

变量定义:整数 (变量名) 等于 (数字)
运算(加法):(变量名) 增加 (数字)
运算(减法):(变量名) 减少 (数字)
输出:看看 (变量名) or 看看 “(字符串内容)”
附加要求:

选择:如果 (判断语句) 则 (操作语句) 否则 (操作语句)
若否则后没有任何操作使用(无)来进行填充(参考样例2)

3.遇到问题:
问题:[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode

参考:https://blog.csdn.net/qq_38316655/article/details/82830565

问题:如何通过 GitHub Desktop 上传代码到 GitHub 远程仓库(暂时未完成)
参考:http://www.bubuko.com/infodetail-2631368.html

4.记录
行数:90
用时:>4天
编译时间: 0.92s

5.代码:

include<stdio.h>

include<string.h>

int trans(char str[])
{
if(strcmp("零",str) == 0)return 0;
if(strcmp("一",str) == 0)return 1;
if(strcmp("二",str) == 0)return 2;
if(strcmp("三",str) == 0)return 3;
if(strcmp("四",str) == 0)return 4;
if(strcmp("五",str) == 0)return 5;
if(strcmp("六",str) == 0)return 6;
if(strcmp("七",str) == 0)return 7;
if(strcmp("八",str) == 0)return 8;
if(strcmp("九",str) == 0)return 9;
if(strcmp("十",str) == 0)return 10;
}

int main(){
char chinese[11] = {"零","一","二","三","四","五","六","七","八","九","十"};
char name[200],verb[200],num[200],oper[200],name1[200],toint[200],name3[200],more[10],less[10];
char a[20],b[20],num2[20],d[20],word[100],e[20],f[20],cold[100],name2[100];
char age[200],money[200];
int sum,sum2,sum3;
scanf("%s",toint);
scanf("%s %s %s",name,verb,num);
if(strlen(num) == 2){
sum = trans(num);/
0-10/
}
while(scanf("%s",name1) != EOF)
{
if(strcmp(name1,toint) == 0)/
第二题/
{
scanf("%s %s %s",name3,verb,num);
sum2 = trans(num);
}
if(strcmp(name1,name) == 0){/
运算,+or-/
scanf("%s",oper);
if(strcmp(oper,"增加") == 0){scanf("%s",num);
if(strlen(num) == 2){
sum3 = trans(num);/
0-10/
}
sum += sum3;
} if (strcmp(oper,"减少") == 0){
scanf("%s",num);
if(strlen(num) == 2){
sum3 = trans(num);/
0-10/
}
sum -= sum3;
}
}
else if(strcmp(name1,"看看") == 0)
{
int lasttmp;
scanf("%s",name);
scanf("%s %s %s %s %s %s %s %s %s %s",a,name,b,num2,d,name2,word,e,f,cold);
lasttmp = trans(num2);
int len = strlen(word);
int len1 = strlen(cold);
{
if(sum >= lasttmp)
{
if(sum >= 0 && sum <= 10){
printf("%s\n",chinese[sum]);
for (int i = 1 ; i < len - 1 ; i += 2){
printf("%c%c",word[i],word[i + 1]);
}
}
} else if(sum < lasttmp){
printf("%s\n",chinese[sum]);
for(int j = 1 ; j < len1 - 1 ; j += 2){
printf("%c%c",cold[j],cold[j+1]);
}
}
}
} else if(strcmp(name1,"如果") == 0){/
第二题/
scanf("%s %s %s %s %s %s %s %s %s",age,b,num2,d,money,word,e,f,cold);
scanf("%s %s", a, age);
if(strcmp(a,"看看") == 0)
{
if(sum>8)/
sum:年龄,sum2:零花钱*/
{
int x = sum2 + 1;
printf("%s",chinese[x]);
}
}
}
}
return 0;
}

6.测试
样例1:

样例2:

测试1:

测试2:

猜你喜欢

转载自www.cnblogs.com/211702335-wanghuimin/p/12289255.html