6 条题解

  • 11
    @ 2024-12-19 16:30:43

    #include<bits/stdc++.h> using namespace std; int main(){ cout<<"hello world"; return 0; }

    • 5
      @ 2025-2-10 20:48:20
      #include<bits/stdc++.h>
      using namespace std;
      constexpr int LEN = 10004;
      int a[LEN], b[LEN], c[LEN], d[LEN];
      void Hello(){
      	cout<<"计算器程序\n可支持10的10000次方位内的运算\n";
      	cout<<"有如下功能\n";
      	cout<<"1.常规运算\n";
      	cout<<"2.面积/体积计算\n";
      	cout<<"3.表达式计算\n";
      	cout<<"4.三角函数\n";
      	cout<<"5.算24点\n";
      	cout<<"请输入一个整数a,表示所需操作,输入0则结束\n";
      }
      struct Gjd{
      	void clear(int a[]){
      		for(int i=0;i<LEN;i++){
      			a[i]=0;
      		}
      	}
      	void read(string s,int a[]){
      		cin>>s;
      		int len=s.size();
      		for(int i=0;i<len;i++){
      			a[len-i-1]=s[i]-'0';
      		}
      	}
      	void print(int a[]){
      		int i;
      		for(i=LEN-1;i>=1;i--){
      			if(a[i]!=0) break;
      		}
      		for(;i>=0;i--){
      			cout<<a[i];
      		}
      		cout<<'\n';
      	}
      	void add(int a[],int b[],int c[]){
      		clear(c);
      		for(int i=0;i<LEN;i++){
      			c[i]+=a[i]+b[i];
      			if(c[i]>=10){
      				c[i+1]+=c[i]/10;
      				c[i]%=10;
      			}
      		}
      	}
      	void sub(int a[],int b[],int c[]){
      		clear(c);
      		for(int i=0;i<LEN-1;i++){
      			c[i]+=a[i]-b[i];
      			if(c[i]<0){
      				c[i+1]-=1;
      				c[i]+=10;
      			}
      		}
      	}
      	void mul(int a[],int b[],int c[]){
      		clear(c);
      		for(int i=0;i<LEN;i++){
      			for(int j=0;j<=i;j++){
      				c[i]+=a[j]*b[i-j];
      			}
      			if(c[i]>=10){
      				c[i+1]+=c[i]/10;
      				c[i]%=10;
      			}
      		}
      	}
      	bool greater_eq(int a[], int b[], int last_dg, int len) {
      		if (a[last_dg + len] != 0) return true;
      		for (int i = len - 1; i >= 0; --i) {
      			if (a[last_dg + i] > b[i]) return true;
      			if (a[last_dg + i] < b[i]) return false;
      		}
      		return true;
      	}
      	void div(int a[], int b[], int c[], int d[]) {
      		clear(c);
      		clear(d);
      		int la, lb;
      		for (la = LEN - 1; la > 0; --la)
      			if (a[la - 1] != 0) break;
      		for (lb = LEN - 1; lb > 0; --lb)
      			if (b[lb - 1] != 0) break;
      		if (lb == 0) {
      			puts("不合法");
      			return;
      		}
      		for (int i = 0; i < la; ++i) d[i] = a[i];
      		for (int i = la - lb; i >= 0; --i) {
      			while (greater_eq(d, b, i, lb)) {
      				for (int j = 0; j < lb; ++j) {
      					d[i + j] -= b[j];
      					if (d[i + j] < 0) {
      						d[i + j + 1] -= 1;
      						d[i + j] += 10;
      					}
      				}
      				c[i] += 1;
      			}
      		}
      	}
      };
      long long binpow(long long a, long long b, long long m){
      	a%=m;
      	long long res=1;
      	while(b>0) {
      		if(b&1) res=res*a%m;
      		a=a*a%m;
      		b>>=1;
      	}
      	return res;
      }
      void cgys(){
      	cout<<"有什么可以帮到你的\n";
      	cout<<"A.加减乘除\n";
      	cout<<"B.开方\n";
      	cout<<"C.一个数的幂次\n";
      	char op;
      	cin>>op;
      	if(op=='A'){
      		cout<<"输入:一个形如 a <op> b 的表达式。\na、b 分别是长度不超过 1000 的十进制非负整数;\n<op> 是一个字符(+、-、* 或 /),表示运算。\n整数与运算符之间由一个空格分隔。\n";
      		Gjd gjd;
      		string s1,s2;
      		char s;
      		gjd.read(s1,a);
      		cin>>s;
      		gjd.read(s2,b);
      		if(s=='+'){
      			gjd.add(a,b,c);
      			gjd.print(c);
      		}
      		else if(s=='-'){
      			gjd.sub(a,b,c);
      			gjd.print(c);
      		}
      		else if(s=='*'){
      			gjd.mul(a,b,c);
      			gjd.print(c);
      		}
      		else if(s=='/'){
      			gjd.div(a,b,c,d);
      			cout<<"商:\n";
      			gjd.print(c);
      			cout<<"余数:\n";
      			gjd.print(d);
      		}
      		else cout<<"不合法";
      	}
      	else if(op=='B'){
      		cout<<"仅可支持10的18次方内的运算\n";
      		cout<<"开几次方\n";
      		int opo;
      		cin>>opo;
      		cout<<"输入操作数\n";
      		unsigned long long s;
      		cin>>s;
      		cout<<"结果为"<<pow(s,1.0/opo)<<'\n';
      	}
      	else{
      		cout<<"仅可支持10的18次方内的运算\n";
      		cout<<"输入底数\n";
      		long long as;
      		cin>>as;
      		cout<<"输入幂数\n";
      		long long k;
      		cin>>k;
      		cout<<"输入模数\n";
      		long long mod;
      		cin>>mod;
      		cout<<binpow(as,k,mod)<<'\n';
      	}
      }
      const double pi=3.14;
      void mtjjs(){
      	cout<<"可计算以下图形/物体的面积/体积\n";
      	cout<<"1.正方形\n2.长方形\n3.平行四边形\n4.三角形\n5.梯形\n6.扇形\n7.扇环\n";
      	int n;
      	cin>>n;
      	if(n==1){
      		cout<<"输入边长:";
      		int ap;
      		cin>>ap;
      		cout<<"S="<<ap*ap;
      	}else if(n==2){
      		cout<<"输入长:";
      		int aa;
      		cin>>aa;
      		cout<<"输入宽:";
      		int ap;
      		cin>>ap;
      		cout<<"S="<<aa*ap;
      	}else if(n==3||n==4){
      		cout<<"输入底:";
      		int aa;
      		cin>>aa;
      		cout<<"输入高:";
      		int ap;
      		cin>>ap;
      		if(n==4){
      			cout<<"S="<<aa*ap*1.0/2<<'\n';
      		}else{
      			cout<<"S="<<aa*ap<<'\n';
      		}
      	}else if(n==5){
      		cout<<"输入上底:";
      		int aa;
      		cin>>aa;
      		cout<<"输入上底:";
      		int ab;
      		cin>>ab;
      		cout<<"输入高:";
      		int ap;
      		cin>>ap;
      		cout<<"S="<<(aa+ab)*ap*0.5;
      	}else if(n==6){
      		cout<<"输入半径:";
      		int r;
      		cin>>r;
      		cout<<"输入圆心角:";
      		int al;
      		cin>>al;
      		long long s=r*r*314*al;
      		long long d=__gcd(s,36000ll);
      		cout<<"S="<<s/d<<'/'<<36000/d;
      	}else if(n==7){
      		cout<<"输入外半径:";
      		int r;
      		cin>>r;
      		cout<<"输入内半径:";
      		int r1;
      		cin>>r1;
      		cout<<"输入圆心角:";
      		int al;
      		cin>>al;
      		printf("%.2lf",(r*r-r1*r1)*pi*al/360.0);
      	}
      }
      struct bdsjs{
      	bool IsOperator(char c) {
      		return c == '+' || c == '-' || c == '*' || c == '/'|| c == '^';
      	}
      // 获取运算符的优先级
      	int GetPriority(char c) {
      		if (c == '+' || c == '-')return 1;
      		if (c == '*' || c == '/')return 2;
      		if (c == '^')return 3;
      		return 0;
      	}
      // 从字符串中读取一个数字,考虑负数的情况
      	string ReadNum(string& str,int& i){
      		string res;
      		if(str[i] == '-'){
      			res += str[i];
      			i++;
      		}
      		while (i < str.size() && isdigit(str[i])) {
      			res += str[i++];
      		}
      		i--;
      		if(res.empty() || res == "-"){cout<<"NO"<<endl;exit(0);}
      		return res;
      	}
      // 将中缀表达式转换为后缀表达式
      	vector<string> InfixToPostfix(string& str) {
      		stack<char> s;
      		vector<string> tokens;
      		bool symbol = false;
      		for (int i = 0; i < str.size(); i++) {
      			if (str[i] == '(') {
      				s.push(str[i]);
      			}
      			else if (str[i] == ')') {
      				while (s.size() && s.top()!= '(') {
      					tokens.push_back(std::string(1, s.top()));
      					s.pop();
      				}
      				s.pop();
      			}else if(!symbol){
      				tokens.push_back(ReadNum(str,i));
      				symbol = true;
      			}else if(IsOperator(str[i])){
      				while (s.size() && GetPriority(str[i]) <= GetPriority(s.top())) {
      					tokens.push_back(std::string(1, s.top()));
      					s.pop();
      				}
      				s.push(str[i]);
      				symbol = false;
      			}
      		}
      		return tokens;
      	}
      	int PostfixToAns(std::vector<std::string>& tokens) {
      		std::stack<int> s;
      		for (int i = 0; i < tokens.size(); i++) {
      			if (isdigit(tokens[i][0]) || tokens[i].size() > 1) {
      				s.push(std::stoi(tokens[i]));
      			}
      			else {
      				int a = s.top();s.pop();
      				int b = s.top();s.pop();
      				if (tokens[i] == "+") {s.push(a + b);}
      				else if (tokens[i]== "-") {s.push(b - a);}
      				else if (tokens[i] == "*") {s.push(a * b);}
      				else if (tokens[i] == "^") {
      					int sum=1;
      					while(a>0){
      						if(a%2!=0)sum=sum*b;
      						b=b*b;
      						a=a>>1;
      					}
      					s.push(sum);
      				}
      				else if (tokens[i] == "/") {if (a == 0) {std::cout<<"NO"<<std::endl;exit(0);}s.push(b / a);}
      			}
      		}
      		return s.top();
      	}
      };
      void bds(){
      	cout<<"输入一个表达式(支持 + - * / ^):";
      	std::string expression;
      	std::cin >> expression;
      //  expression.pop_back();
      	bdsjs js;
      	expression = "(" + expression + ")";
      	std::vector<std::string> tokens = js.InfixToPostfix(expression);
      	int ans = js.PostfixToAns(tokens);
      	cout<<"结果为:"<<ans<<std::endl;
      }
      void sjhs(){
      	cout<<"输入类型:";
      	string s;
      	cin>>s;
      	if(s=="sin"){
      		cout<<"输入弧度:";
      		int p;
      		cin>>p;
      		cout<<sin(p);
      	}else if(s=="cos"){
      		cout<<"输入弧度:";
      		int p;
      		cin>>p;
      		cout<<cos(p);
      	}else{
      		cout<<"输入弧度:";
      		int p;
      		cin>>p;
      		if(cos(p)){
      			cout<<sin(p)*1.0/cos(p)*1.0<<"\n";
      		}
      		else cout<<"不合法";
      	}
      }
      struct Sd{
      	int a[5];
      	char opt[5]={' ','+','-','*','/'};
      	int Js(int x,int k,int y){
      		if(k==1)
      			return x+y;
      		if(k==2)
      			return max(x,y)-min(x,y);
      		if(k==3)
      			return x*y;
      		else
      			if(!y||x<y||!x%y)
      				return -9999;
      			return x/y;
      	}
      	void Out(int a,int b,int c,int d,int e,int f,int k1,int k2,int k3){
      		printf("%d%c%d=%d\n",max(a,b),opt[k1],min(a,b),Js(max(a,b),k1,min(a,b)));
      		printf("%d%c%d=%d\n",max(c,d),opt[k2],min(c,d),Js(max(c,d),k2,min(c,d)));
      		printf("%d%c%d=%d\n",max(e,f),opt[k3],min(e,f),Js(max(e,f),k3,min(e,f)));
      	}
      	void run(){
      		scanf("%d%d%d%d", &a[1],&a[2],&a[3],&a[4]);
      		sort(a+1,a+5);                                            //保证遍历所有情况
      		do{
      			for (int i = 1; i <= 4; i++){
      				for (int j = 1; j <= 4; j++){
      					for (int k = 1; k <= 4; k++){
      						if (Js(Js(Js(a[1],i,a[2]),j,a[3]),k,a[4])==24){
      							Out(a[1],a[2],Js(a[1],i,a[2]),a[3],Js(Js(a[1],i,a[2]),j,a[3]),a[4],i,j,k);
      							return;
      						}     //((a?b)?c)?d
      						else if (Js(Js(a[1],i,a[2]),k,Js(a[3],j,a[4])) == 24){
      							Out(a[1],a[2],a[3],a[4],Js(a[1],i,a[2]),Js(a[3],j,a[4]),i,j,k);
      							return;
      						}
      					}
      				}
      			}                         //暴力枚举3个运算符
      		}  while (next_permutation(a + 1, a + 5));
      		puts("No answer!");
      	}
      };
      void s24d(){
      	cout<<"输入四个1到9之间的自然数(所有运算结果均为正整数。):\n";
      	Sd sd;
      	sd.run();
      }
      int main(){
      	Hello();
      	int a;
      	cin>>a;
      	while(a){
      		if(a==1){
      			cgys();
      		}
      		else if(a==2){
      			mtjjs();
      		}
      		else if(a==3){
      			bds();
      		}
      		else if(a==4){
      			sjhs();
      		}
      		else{
      			s24d();
      		}
      		cout<<'\n';
      		Hello();
      		cin>>a;
      	}
      	return 0;
      }
      
      • 4
        @ 2025-1-10 16:50:57

        #include<bits/stdc++.h> using namespace std; int main(){ cout<<"我要网暴邱禹皓"<<endl; return 0; }

        • @ 2025-1-10 16:52:11

          我是农民,这就是甜菜

        • @ 2025-1-10 16:53:09

          我TM#@¥……@#……¥&#@……&¥……@#……¥&@T#&!……@%#%!%R&!……#@%E#@%&!@R#%!@!@%

        • @ 2025-1-10 17:00:36

          时代邱禹皓我要网暴你,网暴你,网暴你,网暴你,网暴你,网暴你,网暴你,网暴你,网暴你,网暴你,网暴你。

        • @ 2025-1-10 17:01:43

          @

        • @ 2025-1-10 17:02:51

          tmd

        • @ 2025-1-11 9:36:57

          我嘞个豆啊

      • 2
        @ 2025-4-29 9:20:09

        #include<bits/stdc++.h> using namespace std; int main(){ cout<<"hello world"; return 0; }

        • 1
          @ 2026-3-1 14:23:33

          这道题是最基础的题,代码是:

          #include<bits/stdc++.h> using namespace std; int main(){ cout<<"hello world"<<endl; return 0; }

          • -1
            @ 2025-8-13 12:58:43
            #include<bits/stdc++.h>
            using namespace std;
            #define ll long long 
            ll n,mx=LONG_LONG_MIN,l;
            int main(){
            	ios_base::sync_with_stdio(0);
            	cout.tie(0);
            	cin.tie(0);
            	freopen("game.in","r",stdin);
            	freopen("game.out","w",stdout);
            	
            	cin>>n;
            	ll m=1;
            	for(ll i=1;i<=n;i++){
            		m*=2;
            	}
            	n=m;
            	for(ll i=1;i<=n;i++){
            		ll x;
            		cin>>x;
            		ll p=mx;
            		mx=max(mx,x);
            		if(mx!=p){
            			l=i;
            		}
            	}
            	cout<<l;
            	return 0;
            }
            
            • 1

            信息

            ID
            2
            时间
            1000ms
            内存
            512MiB
            难度
            7
            标签
            递交数
            511
            已通过
            116
            上传者