61 条题解

  • -1
    @ 2023-2-16 18:31:29
    #include <bits/stdc++.h> 
    using namespace std;
    int main()
    {
    int a;
    cin>>a;
    if(a%2==1)
    {
        cout<<a/2+a%2;
    } 
    else
    {
        cout<<a+1;
    }
        
        return 0;
    }
    
    
    • -1
      @ 2023-1-20 16:02:38
      #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              int n;
              cin >> n;
              if (n%2==1)
              {
                  cout << n/2+1;
              }
              else
              {
                  cout << n+1;
              }
              return 0;
          }
      
      • -1
        @ 2023-1-18 11:46:29

        最短行

        #include <iostream>
        using namespace std;
        int main()
        {
            int n; cin >> n; if(n%2==1) cout << n/2+1; else cout << n/2+n/2+1;
        }
        
      • -1
        @ 2022-9-30 21:36:58

        这个题必须要用万能头文件 代码开始 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n%2==1) { cout << n/2+1; } else { cout << n+1; } return 0; }

        • -1
          @ 2022-8-31 10:35:22
          #include<iostream>
          using namespace std;
          int main()
          {
              int n;
              cin>>n;
             if(n%2==0)
             {
              cout<<n/2+1+n/2;
             }
             else
             {
             cout<<n/2+1;
             }
              return 0;
          }
          
          • -1
            @ 2022-8-19 9:18:16
            #include <iostream>
            using namespace std;
            int main(){
                int n;
                cin>>n;
                if (n%2==1){
                    cout<<(n+1)/2;
                }
                if (n%2==0){
                    cout<<n/2+n/2+1;
                }
                return 0;
            }
            
            • -1
              @ 2022-8-13 16:49:30
              if (n%2 == 0)
                  cout << n+1;
              else
                   cout << n/2+1;
              
              • -1
                @ 2022-8-5 9:44:35
                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    int n;
                    cin>>n;
                    int x= n%2==0? n+1:n/2+1;
                    cout<<x;
                }
                

                我还是喜欢简洁的

                int x= n%2==0? n+1:n/2+1;
                

                这个意思是n%2==0t为true输出n+1,否则输出后面的

                • -1
                  @ 2022-5-23 17:03:48

                  题解:n为奇数中间数为n/2+1,n为偶数中间数是n/2和n/2+1,两个数求和化简为n+1。

                • -2
                  @ 2024-1-3 20:41:48
                  #include <iostream>
                  using namespace std;
                  int main()
                  {
                      int n,p = 0;
                      cin >> n;
                      if (n % 2 == 1)
                      {
                          p = n / 2 + 1;
                      }
                      else
                      {
                          p = n + 1;
                      }
                      cout << p << endl;
                      return 0;
                  }
                  
                  • -2
                    @ 2024-1-1 23:15:40
                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        int n;
                        cin >> n;
                        if (n % 2 == 1)
                        {
                            cout << (n + 1) / 2;
                        }
                        else
                        {
                            cout << n + 1;
                        }
                        return 0;
                    }
                    

                    点个赞吧

                    • -2
                      @ 2024-1-1 19:42:05

                      #include <iostream> using namespace std; int main () { int n,sum=0; cin>>n; if (n%2==1) { sum+=n/2+1; } else { sum+=n/2+n/2+1; } cout<<sum; return 0;

                      }

                      • -3
                        @ 2022-9-12 17:00:14

                        if语句 #include <iostream> using namespace std; int n; int main() { cin >> n; if (n % 2 == 1) { cout << (n+1) / 2; } else { cout << 2 * (n/2) + 1; } }

                        • -3
                          @ 2022-8-23 20:39:00

                          #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 1)//判断奇偶数 { cout << n / 2 + 1;//找规律 } else { cout << n + 1;//找规律 } return 0; }

                          • -3
                            @ 2022-7-20 11:14:25
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int n;
                                    cin >> n;
                                    if (n%2 == 1)
                                    {
                                        cout << (n+1)/2;
                                    }
                                    else
                                    {
                                        cout << n+1;
                                    }
                                    return 0;
                                }
                            
                            • -5
                              @ 2022-7-6 7:23:55
                              if(n % 2 == 0)//偶数情况
                              {
                              cout << n + 1;
                              }
                              else//奇数情况
                              {
                              cout << n / 2 + 1;
                              }
                              
                              
                              
                              
                              
                              
                              
                              • -5
                                @ 2022-6-12 12:23:27

                                #include <iostream> using namespace std; int main() { int a; int sum=0; cin >> a; for(int i=1;i<=a;i++) { sum += i*i; } cout << sum ; return 0; }

                                • -5
                                  @ 2022-6-10 23:05:47

                                  #include<iostream> using namespace std; int main() { int n; cin >> n; if (n%2==1) { cout << n/2+1; } else { cout << n+1; } return 0; }

                                  • -6
                                    @ 2022-8-23 18:57:44
                                    #include<iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int n;
                                        cin>>n;
                                        if(n%2==1)//判断奇偶数
                                        {
                                            cout<<(      );//输出中间数
                                        }
                                        else
                                        {
                                            cout<<(      );//输出两数之和
                                        }
                                        return 0;
                                    }
                                    
                                    • @ 2022-8-23 18:59:59

                                      这题的输出和计算是关键 提示: 奇数可以+1使其变成偶数

                                  • -6
                                    @ 2022-8-22 21:08:46

                                    嘻嘻,简洁的代码来喽!!

                                    image

                                    #include<bits/stdc++.h>
                                    using namespace std;
                                    int main(){
                                        int n;
                                        cin >> n;
                                        if(n % 2 == 1) cout << n / 2 + 1 << endl;
                                        else cout<< n + 1 << endl;
                                        return 0;
                                    }
                                    

                                    信息

                                    ID
                                    555
                                    时间
                                    1000ms
                                    内存
                                    128MiB
                                    难度
                                    4
                                    标签
                                    递交数
                                    9129
                                    已通过
                                    4276
                                    上传者