3 条题解

  • 2
    @ 2023-6-16 20:34:38
    #include <iostream>
    using namespace std;
    int main()
    {
    	int n,x = 0,y = 0; 
        cin >> n;
        for (int i = 1; i <= n; i += 2)
        {
            x += i;
        }
        for (int i = 2; i <= n; i += 2)
        {
            y += i;
        }
        cout << x << " " << y;
    	return 0;
    }
    
    • 1
      @ 2023-8-9 22:42:09
      #include <bits/stdc++.h>
      using namespace std;
      int n,a,b;//a代表奇数和,b代表偶数和
      int main()
      {
          cin>>n;
          for(int i=1;i<=n;i++)//遍历1~n
          {
              if(i%2==1)//如果是奇数
                  a+=i;//a加上i
              if(i%2==0)//如果是偶数
                  b+=i;//b加上i
          }
          cout<<a<<" "<<b;//输出a和b
          return 0;
      }
      
      • -1
        @ 2022-4-11 13:41:22

        #include<bits/stdc++.h> using namespace std; int main() { int n,sumj=0,sumo=0; cin>>n; for(int i=1;i<=n;i++) { if(i%2==0)sumo+=i; else sumj+=i;

        }
        cout<<sumj<<' '<<sumo;
        return 0;
        

        }

        • 1

        信息

        ID
        92
        时间
        1000ms
        内存
        32MiB
        难度
        3
        标签
        递交数
        244
        已通过
        129
        上传者