用户:
牢大编程师查看:20 回复:11 评论:20 创建时间:2024-07-24T13:07:49
有谁会DEV-C++吗
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,b,o,t;
string f;
cout<<"输入第一个数,再输入运算符号,接着第二个数,然后enter\n";
while(1){ //重复判断
cin>>a;
cin>>f;
cin>>b;
if(f=="+"){ //加法运算
o=a+b;
cout<<a<<"+"<<b<<"="<<o;
}
if(f=="-"){ //减法运算
o=a-b;
cout<<a<<"-"<<b<<"="<<o;
}
if(f=="*"){ //乘法运算
o=a*b;
cout<<a<<"*"<<b<<"="<<o;
}
if(f=="/"){ //除法运算
o=a/b;
cout<<a<<"/"<<b<<"="<<o;
}
}
return 0;
}点赞0
评论
PlumSteven1年前写的垃圾计算器
#include <bits/stdc++.h>
using namespace std;
stack<char> infixOperatorStack;
stack<long long> numberStack;
map<char, int> operatorPriority;
bool isDigit(char c){
return (c>='0'&&c<='9');
}
int main()
{
operatorPriority['+']=1;
operatorPriority['*']=2;
string in;
cin>>in;
string rpn; //后缀表达式
for(int i=0;i<in.length();i++){
if(isDigit(in[i])){
rpn+=in[i];
} else{ //是运算符
rpn+="@"; //使用@分割每个数字
while(!(infixOperatorStack.empty()||operatorPriority[in[i]]>operatorPriority[infixOperatorStack.top()])){
rpn+=infixOperatorStack.top();
infixOperatorStack.pop(); //如果优先级低,弹出
}
infixOperatorStack.push(in[i]);
}
}
rpn+='@';
while(!infixOperatorStack.empty()){ //弹出栈内所有操作符
rpn+=infixOperatorStack.top();
infixOperatorStack.pop();
}
long long num=0;
for(int i=0;i<rpn.length();i++){
if(isDigit(rpn[i])){
num*=10;
num+=(rpn[i]-'0');
} else if(rpn[i]=='@'){
numberStack.push(num%10000);
num=0;
} else{
long long oa = numberStack.top();
numberStack.pop();
long long ob = numberStack.top();
numberStack.pop();
switch(rpn[i]){
case '+':
numberStack.push((oa+ob)%10000);
break;
case '*':
numberStack.push((oa*ob)%10000);
break;
}
}
}
if(!numberStack.empty()) cout<<numberStack.top();
else{
cout<<num;
}
return 0;
}点赞0
评论
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
long long num;
cout << "请输入起始数字:";
cin >> num;
while(true)
{
cout << "当前数值:" << num << endl;
if(num % 2 == 1)
{
// 单数 乘以2
num = num * 2;
cout << "判定单数,执行 ×2\n";
}
else
{
// 双数 除以2再加1
num = num / 2 + 1;
cout << "判定双数,执行 ÷2 +1\n";
}
cout << "-----------------\n";
Sleep(1000); // 间隔1秒运算
}
return 0;
}
点赞0
评论