连辛集

导航

 
这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/SE
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/SE/homework/10283
这个作业的目标 重新捡起大一拉下的C语言的有关知识
作业正文 见下文
其他参考文献 参考百度的各种资料,以及去其他大佬的博客获取知识

代码行数:158行
需求分析:2hour
代码编写:2天

github的地址:https://github.com/1791593280/1.homework/blob/master/first.cpp

所遇到的问题:
1,对C语言的陌生,以及一些语法的遗忘
2,对题目的意思了解不够全面
3,对题目的思路不过清晰,需借鉴百度以及各位博客大佬的知识

代码如下:

include<stdio.h>

include<string.h>

include<math.h>

int first(char a[])
{
if(strcmp("零",a)0)
return 0;
if(strcmp("一",a)
0)
return 1;
if(strcmp("二",a)0)
return 2;
if(strcmp("三",a)
0)
return 3;
if(strcmp("四",a)0)
return 4;
if(strcmp("五",a)
0)
return 5;
if(strcmp("六",a)0)
return 6;
if(strcmp("七",a)
0)
return 7;
if(strcmp("八",a)0)
return 8;
if(strcmp("九",a)
0)
return 9;
if(strcmp("十",a)0)
return 10;
}
int second(char a[]){
char b[10],c[10];
if(strlen(a)
2)
{
return first(a);
}
else if(strlen(a)==4)
{
b[0]=a[2];
b[1]=a[3];
b[2]='\0';
if(first(b)!=10)
return 10+first(b);
else{
b[0]=a[0];
b[1]=a[1];
b[2]='\0';
return 10*first(b);
}

}
else if(strlen(a)==6)
{
    b[0]=a[4];
    b[1]=a[5];
    b[2]='\0';
    c[0]=a[0];
    c[1]=a[1];
    c[2]='\0';
    return first(b)+first(c)*10;
}

}
int main(){
char *chinese[11]={"零","一","二","三","四","五","六","七","八","九","十"};
char name[200],verb[200],numb[200],oper[200],name1[200],toint[200],name3[200];
char x[20],y[20],numb2[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,numb);
sum=second(numb);
while(scanf("%s",name1)!=EOF)
{
if(strcmp(name1,toint)0)
{
scanf("%s %s %s",name3,verb,numb);
sum2=first(numb);
}
if(strcmp(name1,name)
0){
scanf("%s",oper);
if(strcmp(oper,"增加")0){
scanf("%s",numb);
sum3=second(numb);
sum+=sum3;}
if(strcmp(oper,"减少")
0){
scanf("%s",numb);
if(strlen(numb)2)
{
sum3=second(numb);
sum-=sum3;
}
}
}
else if(strcmp(name1,"看看")
0)
{
int lasttmp;
scanf("%s",name);
scanf("%s %s %s %s %s %s %s %s %s %s",x,name,y,numb2,d,name2,word,e,f,cold);
lasttmp=first(numb2);
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%100){
printf("%s十\n",chinese[sum/10]);for (int i=1;i<len-1; i+=2) {printf("%c%c",word[i],word[i+1]);}
}
else if(sum<=19){
printf("十%s\n",chinese[sum%10]);for (int i=1;i<len-1; i+=2) {printf("%c%c",word[i],word[i+1]);}
}
else {
printf("%s十%s\n",chinese[sum/10],chinese[sum%10]);for (int i=1;i<len-1; i+=2) {printf("%c%c",word[i],word[i+1]);}
}
}
}
else if(sum<lasttmp){
if(sum<0)
{
int under=abs(sum);
printf("%s%s\n","负",chinese[under]);
for(int j=1;j<len1-1;j+=2) {printf("%c%c",cold[j],cold[j+1]);}}
}
else{
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,y,numb2,d,money,word,e,f,cold);
scanf("%s %s",x,age);
if(strcmp(x,"看看")==0)
{
if(sum>8)
{
int x=sum2+1;
printf("%s",chinese[x]);
}
}
}
}
return 0;
}

样例1:
整数 气温 等于 十
气温 减少 三
气温 增加 二
看看 气温
如果 气温 大于 八 则 看看 “你好,世界” 否则 看看 “冻死我了”

输出:

样例2:
整数 小杨年龄 等于 八
整数 小杨零花钱 等于 二
小杨年龄 增加 一
如果 小杨年龄 大于 八 则 小杨零花钱 增加 一 否则 无
看看 小杨零花钱

输出:

posted on 2020-02-08 12:39  志远行止  阅读(711)  评论(1编辑  收藏  举报