10 条题解

  • 5
    @ 2022-1-8 10:56:36
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    int main()
    {
        int l,r;
        cin >> l >> r;
        int sum = 0;
        for(int i = l; i <= r ; i++)
        {
            int g,s,b;
            g = i%10;
            b = i/100;
            s = i/10%10;
            if(g*g*g + s*s*s + b*b*b == i)
            {
                cout << i << " ";
                sum++;
            }
        }
        if(sum == 0)
        {
            cout << "No Answer.\n";
        }
        else
        {
            cout << endl << sum << endl;
        }
    
    }
    
    • 3
      @ 2022-12-20 21:45:04

      水题。 AC代码:

      #include<iostream>
      #include<math.h>
      using namespace std;
      int m,n;
      bool check(int x){//自定义函数
      	int s=0,y=x;
      	while(y!=0){
      		s+=pow(y%10,3);//求每个数位上的数的立方
      		y/=10;//删除当前数位
      	}
      	if(s==x)return true;//是水仙花数
      	else return false;//不是水仙花数
      }
      int main(){
      	int sum;
      	cin>>m>>n;
      	for(int i=m;i<=n;i++){
      		if(check(i)){//引用自定义函数
      			cout<<i<<" ";
      			sum++;
      		}
      	}
      	if(sum>0)cout<<endl<<sum;//有水仙花数
      	else cout<<"No Answer.";//没有水仙花数
      	return 0;
      }
      

      无注释纯净版:

      #include<iostream>
      #include<math.h>
      using namespace std;
      int m,n;
      bool check(int x){
      	int s=0,y=x;
      	while(y!=0){
      		s+=pow(y%10,3);
      		y/=10;
      	}
      	if(s==x)return true;
      	else return false;
      }
      int main(){
      	int sum;
      	cin>>m>>n;
      	for(int i=m;i<=n;i++){
      		if(check(i)){
      			cout<<i<<" ";
      			sum++;
      		}
      	}
      	if(sum>0)cout<<endl<<sum;
      	else cout<<"No Answer.";
      	return 0;
      }
      

      可能或许大概稍微写得难了一点点。。。点个赞再走吧!

      • 1
        #include<iostream>
        using namespace std;
        int sum=0,n,m,ge,shi,bai;
        int main()
        {
            cin>>n>>m;
        	for(int i=n;i<=m;i++) 
        	{
        		ge=i%10;
        		shi=i/10%10;
        		bai=i/100;
        		if(ge*ge*ge+shi*shi*shi+bai*bai*bai==i && i>99 && i<999)
        		{
        		sum++;
        		cout<<i<<" ";	
        		} 
        	}
        	if(sum==0)
        	cout<<"No Answer."; 
        	else
        	cout<<endl<<sum;
            return 0;
        }
        
        • 1
          @ 2023-3-5 19:59:12
          #include<queue>
          #include<math.h>
          #include<stack>
          #include<stdio.h>
          #include<iostream>
          #include<vector>
          #include<iomanip>
          #include<string.h>
          #include<algorithm>
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              int l,r;
              cin>>l>>r;
              int sum=0;
              for(int i=l;i<=r;i++){
                  int g,s,b;
                  g=i%10;
                  b=i/100;
                  s=i/10%10;
                  if(g*g*g+s*s*s+b*b*b==i){
                      cout<<i<<" ";
                      sum++;
                  }
              }
              if(sum==0){
                  cout<<"No Answer.\n";
              }
              else{
                  cout<<endl<<sum<<endl;
              }
          	return 0;
          }
          
          • 0
            @ 2023-12-27 18:29:24
            • #include <iostream> using namespace std; const int N=1e3+10; const int INF=0x3f3f3f3f; int n,m,g,s,b,cnt; void flower(int n,int m) {

              for(int i=n;i<=m;i++) { g=i%10; b=i/100; s=i/10%10; if(ggg+sss+bbb==i) { cout<<i<<" "; cnt++; } } if(cnt) cout<<endl<<cnt; else cout<<"No Answer."; } int main(){ cin>>n>>m; flower(n,m); }

            • -1
              @ 2023-3-22 20:10:44

              #include <iostream> #include<cmath> using namespace std; int m,n,sum=0; int main(){ cin>>m>>n; for(int i=m;i<=n;i++){ int g,s,b; g=i%10; b=i/100; s=i/10%10; if (ggg+sss+bbbi){ cout << i <<" "; sum++; } } if (sum0){ cout << "No Answer."; } else{ cout << endl << sum ; } return 0;

              1. }
              • -1
                @ 2022-1-23 13:05:13
                #include <iostream>
                #include <stdio.h>
                #include <string.h>
                #include <queue>
                #include <math.h>
                #include <vector>
                #include <algorithm>
                #include <iomanip>
                #include <stack>
                
                using namespace std;
                
                #define LL long long
                const int N =1e5+10;
                const int INF =0x3f3f3f3f;
                int a[N];
                int f(int x){
                    int y=0;
                    while(x){
                        a[y]=x%10;
                        y++;
                        x/=10;
                    }
                    return y;
                }
                int main(){
                    int n,m,cnt,ans=0;
                    cin>>n>>m;
                    for(int i=n;i<=m;i++){
                        cnt=f(i);
                        int sum=0;
                        for(int j=0;j<cnt;j++){
                            sum+=a[j]*a[j]*a[j];
                        }
                        if(sum==i){
                            cout<<i<<" ";
                            ans++;
                        }
                    }
                    cout<<endl;
                    if(ans)
                        cout<<ans<<endl;
                    else
                        cout<<"No Answer."<<endl;
                    return 0;
                }
                • -1
                  @ 2022-1-8 10:53:11
                  #include <stdio.h>
                  #include <iostream>
                  using namespace std;
                  int main()
                  {
                      int l,r;
                      cin >> l >> r;
                      int sum = 0;
                      for(int i = l; i <= r ; i++)
                      {
                          int g,s,b;
                          g = i%10;
                          b = i/100;
                          s = i/10%10;
                          if(g*g*g + s*s*s + b*b*b == i)
                          {
                              cout << i << " ";
                              sum++;
                          }
                      }
                      if(sum == 0)
                      {
                          cout << "No Answer.\n";
                      }
                      else
                      {
                          cout << endl << sum << endl;
                      }
                  
                  }
                  
                  • -2
                    @ 2022-1-8 10:52:07
                    #incl···ude <math.h>
                    #include <iomanip>
                    using namespace std;
                    int main()
                    {
                        int l,r;
                        cin >> l >> r;
                        int sum = 0;
                        for(int i = l; i <= r ; i++)
                        {
                        	int g,s,b;
                        	g = i%10;
                        	b = i/100;
                        	s = i/10%10;
                        	if(g*g*g + s*s*s + b*b*b == i)
                        	{
                        		cout << i << " ";
                        		sum++;
                    		}
                    	}
                    	if(sum == 0)
                    	{
                    		cout << "No Answer.\n";
                    	}
                    	else
                    	{
                    		cout << endl << sum << endl;
                    	}
                    }
                    • -5
                      @ 2022-10-19 21:48:44
                      using namespace std;
                      int main(){
                      	int m,n,s=0;
                      	cin>>m>>n;
                      	for(int i=m;i<=n;i++){
                      		if((i/100)*(i/100)*(i/100)+(i/10%10)*(i/10%10)*(i/10%10)+(i%10)*(i%10)*(i%10)==i){
                      			cout<<i<<" ";
                      			s++;
                      		}
                      	}
                              cout<<endl;
                      	if(s==0){
                      		cout<<"No Answer.";
                      	}else{
                      		cout<<s<<endl;
                      	}
                      }
                      
                      • 1

                      信息

                      ID
                      898
                      时间
                      1000ms
                      内存
                      128MiB
                      难度
                      6
                      标签
                      递交数
                      1290
                      已通过
                      373
                      上传者