cpp编程吧 关注:19贴子:477
  • 17回复贴,共1
代码格式

标题:
代码:


1楼2013-07-27 19:14回复
    题目:一年中的第几天(哈西做法)
    代码:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main(int argc, char *argv[])
    {


    6楼2013-07-27 19:21
    回复
      int y, m, d;
      int s[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
      int n, i;
      cin >> y >> m >> d;


      7楼2013-07-27 19:22
      回复
        cout << n << endl;
        system("PAUSE");
        return EXIT_SUCCESS;
        }
        大家参考一下吧!


        9楼2013-07-27 19:22
        回复
          灌水请移驾灌水帖 http://tieba.baidu.com/p/2480503636


          18楼2013-07-27 19:36
          回复
            #include <cstdlib>
            #include <iostream>
            using namespace std;
            int main(int argc, char *argv[])
            {
            int s[500000], i, j, k;
            int n;
            cin >> n;
            for ( i = 2; i <= n; i++ )
            s[i] = 1;
            for ( i = 2; i <= n; i++ )
            {
            if ( s[i] == 1 )
            for ( j = 2 * i; j <= n; j += i )
            s[j] = 0;
            }
            for ( i = 2; i <= n; i++ )
            if ( s[i] == 1 )
            {
            cout << i << " ";
            k++;
            }
            cout << endl << "共" << k << "个质数";
            cout << endl;
            system("pause");
            return 0;
            }


            22楼2013-07-27 20:56
            回复
              以上代码为筛法求质


              23楼2013-07-27 20:57
              回复
                AllanGong法


                24楼2013-07-27 20:58
                回复
                  由他本人发布


                  25楼2013-07-27 20:58
                  收起回复
                    #include <cstdlib>
                    #include <iostream>
                    #include <math.h>
                    using namespace std;
                    int main(int argc, char *argv[])
                    {
                    int i, j, n1, s[50001] = {};
                    double n;
                    for (i = 2; i <= 50000; i++)
                    {
                    s[i] = 1;
                    }
                    n = sqrt(50000);
                    for (i = 2; i <= n; i++)
                    {
                    if (s[i] == 0)
                    continue;
                    for (j = 2 * i; j <= 50000; j += i)
                    {
                    s[j] = 0;
                    n1++;
                    }
                    }
                    for (i = 2; i <= 50000; i++)
                    {
                    if (s[i] == 1)
                    cout << i << " ";
                    }
                    cout << endl;
                    cout << "共" << n1 << "个质数" << endl;
                    system("PAUSE");
                    return EXIT_SUCCESS;
                    }
                    我的比吴子睿522快。


                    IP属地:北京26楼2013-07-27 21:00
                    回复


                      IP属地:北京27楼2013-07-28 16:13
                      回复
                        #include <iostream>#include <cstring>#include <cstdlib>#include <cmath>
                        using namespace std;
                        int main(int argc, char *argv[]){ int n; int i; int a[ 200 ]; int m; int s( 0 ); cin >> n; for ( i = 1 ; i <= n ; i++ ) cin >> a[ i ]; i = 0; cin >> m; for ( i = 1 ; i<=n ; i++ ) if( a[ i ] > m ) s++; cout << s + 1 << endl; //system("PAUSE"); return EXIT_SUCCESS;}


                        IP属地:北京28楼2013-07-28 16:14
                        回复
                          题目:本次作业
                          #include <cstdlib>#include <iostream>#include <cmath>#include <cstring>
                          using namespace std;
                          int main(int argc, char *argv[]){ int n; int i; int j; int k; cin >> n; i = 0; while ( n != 0 ) { i = n % 2; n = n / 2; cout << i ; i = n; } cout << endl; system("PAUSE"); return EXIT_SUCCESS;}


                          IP属地:北京29楼2013-07-28 18:37
                          收起回复


                            IP属地:北京30楼2013-08-19 09:07
                            回复
                              早上好!


                              IP属地:北京31楼2013-08-19 09:09
                              回复