提交记录 #524
提交时间:2025-01-04 17:50:02
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:62:5: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
62 | gets(str);
| ^~~~
| fgets
code.c:79:5: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
79 | printf("%d\n",n);
| ^~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cctUgmg6.o: in function `main':
code.c:(.text.startup+0x1b): warning: the `gets' function is dangerous and should not be used.
固定测试点#1:
固定测试点#2:
额外测试点#1:
H22【选做▪应用】逆波兰算术表达式
#include<stdio.h>
#include<string.h>
#include<math.h>
char str[100],s; int n1=0,n2=0;
int findnum1(int i)
{
int count=0;
for(;i>=0;i--)
{
if(str[i]==' '&&count!=0)break;
else if(str[i]==' ')continue;
n1+=(str[i]-48)*pow(10,count);
str[i]=' ';
count++;
}
return i;
}
int findnum2(int i)
{
int count=0;
for(;i>=0;i--)
{
if(str[i]==' '&&count!=0)break;
else if(str[i]==' ')continue;
n2+=(str[i]-48)*pow(10,count);
str[i]=' ';
count++;
}
return i;
}
int findsym()
{
int i=0;
for(i=0;i<strlen(str);i++)
{
if(str[i]=='+'||str[i]=='-'||str[i]=='*'||str[i]=='/')
{
s=str[i];return i-1;
}
}
return -1;
}
void remake(int n,int i)
{
char c[10];int j=0,J;
for(j=0;;j++)
{
c[j]=n%10+48;
n=n/10;
if(n==0)break;
}
J=j+1;
for(j=0;j<J;j++)
{
str[i-j]=c[j];
}
}
int main()
{
int i,j,I,n;
gets(str);
for(j=0;;j++)
{
n1=0;n2=0;
i=findsym();I=i+1;
if(i==-1)break;
i=findnum1(i);
i=findnum2(i);
switch(s)
{
case '+' :n=n1+n2;break;
case '-' :n=n2-n1;break;
case '*' :n=n2*n1;break;
case '/' :n=n2/n1;break;
}
remake(n,I);
}
printf("%d\n",n);
return 0;
}