求调:
  • 板块题目总版
  • 楼主dengruixun
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/4 17:27
  • 上次更新2023/11/3 05:55:10
查看原帖
求调:
667679
dengruixun楼主2023/8/4 17:27

题目:

【输入样例】

16 9 4 3 +*-@

【输出样例】

-47

代码:

#include<bits/stdc++.h>
using namespace std;
int stak[101];
char s[256];
int comp(char s[256]){
	int i = 0,top = 0,x,y;
	while(i<=strlen(s)-2){
		switch(s[i]){
			case '+':stak[--top] += stak[top+1];break;
			case '-':stak[--top] -= stak[top+1];break;
			case '*':stak[--top] *= stak[top+1];break;
			case '/':stak[--top] /= stak[top+1];break;
			default:
				x = 0;
				while(s[i]!=' '){
					x = x * 10 + s[i++] - '0';
				}
				stak[++top] = x;break;
		}
		i++;
	}
	return stak[top];
}
main(){
	printf("input a string(@_over):");
	gets(s);
	printf("result=%d",comp(s));
	return 0;
}

错误:

24588785.cpp: In function ‘int comp(char*)’:
24588785.cpp:7:9: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
7 | while(i<=strlen(s)-2){
| ~^~~~~~~~~~~~~
24588785.cpp:9:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
9 | case '+': stak[--top] += stak[top+1];break;
| ^~~~~
24588785.cpp:9:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
24588785.cpp:10:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
10 | case '-': stak[--top] -= stak[top+1];break;
| ^~~~~
24588785.cpp:10:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
24588785.cpp:11:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
11 | case '*': stak[--top] *= stak[top+1];break;
| ^~~~~
24588785.cpp:11:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
24588785.cpp:12:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
12 | case '/': stak[--top] /= stak[top+1];break;
| ^~~~~
24588785.cpp:12:19: warning: operation on ‘top’ may be undefined [-Wsequence-point]
24588785.cpp:6:22: warning: unused variable ‘y’ [-Wunused-variable]
6 | int i = 0,top = 0,x,y;
| ^
24588785.cpp: At global scope:
24588785.cpp:24:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
24 | main(){
| ^
24588785.cpp: In function ‘int main()’:
24588785.cpp:26:2: error: ‘gets’ was not declared in this scope; did you mean ‘fgets’?
26 | gets(s);
| ^~~~
| fget
2023/8/4 17:27
加载中...