你就是根基吧 关注:7贴子:115
  • 10回复贴,共1

程序猿根基

只看楼主收藏回复



1楼2014-10-19 23:16回复
    #include<iostream>
    using namespace std;
    int main()
    {
    int n;
    int a, b, c, max, mid;
    cin >> n;
    cin >> a >> b >> c;
    if(a>b)
    {
    if(b>c) max=a, mid=b;
    else
    {
    if(a>c) max=a, mid=c;
    else max=c, mid=a;
    }
    }
    else
    {
    if(a>c) max=b, mid=a;
    else
    {
    if(c>b) max=c, mid=b;
    else max=b, mid=c;
    }
    }
    cout << max <<" "<<mid<< endl;
    return 0;
    }


    2楼2014-10-19 23:16
    回复
      #include<iostream>
      #include<iomanip>
      using namespace std;
      int main()
      {
      int n;
      cin >> n;
      if(n==1)
      for(int i=1;i<=6;i++)
      for(int a=1;a<=i;a++)
      {
      cout << setw(3) << a;
      if(a==i)
      cout << endl;
      }
      if(n==2)
      for(int i=6;i>=1;i--)
      for(int a=1;a<=i;a++)
      {
      cout << setw(3) << a;
      if(a==i)
      cout << endl;
      }
      if(n==3)
      for(int i=1;i<=6;i++)
      {
      for(int b=6;b>i;b--)
      cout << setw(3) << " ";
      for(int a=1;a<=i;a++)
      {
      if(a<=i) cout << setw(3)<< a;
      if(a==i)
      cout << endl;
      }
      }
      if(n==4)
      for(int i=6;i>=1;i--)
      {
      for(int b=6;b<i;b--)
      cout << setw(3) << " ";
      for(int a=1;a<=i;a++)
      {
      if(a<=i) cout << setw(3)<< a;
      if(a==i)
      cout << endl;
      }
      }
      return 0;
      }


      3楼2014-10-27 17:07
      回复
        #include<iostream>
        using namespace std;
        int main()
        {
        int a,b;
        cin>>a>>b;
        int i;
        if(a>b) i=b;
        else i=a;
        for (;i>=1;i--)
        {
        if(a%i == 0 && b%i == 0)
        break;
        }
        cout << i << endl;
        return 0;
        }


        4楼2014-11-03 16:44
        回复
          int sumDigits(long n)
          {
          int a,b,c,sum;
          n=fabs(n);
          a=n/100;
          b=(n-100a)/10;
          c=n%10;
          sum=a+b+c;
          }


          5楼2014-11-03 16:51
          回复
            #include<iostream>
            using namespace std;
            int main()
            {
            int year,month,n;
            cin >> year >> month;
            switch(month)
            {
            case 1:
            n=31;
            cout << "January " << year << " has " << n <<" days" ;break;
            case 2: if((year%4==0&&year%100!=0)||year%400==0)n=29;
            else n=28;
            cout << "February " << year << " has " << n <<" days" ;break;
            case 3: n=31;
            cout << "March " << year << " has " << n <<" days" ;break;
            case 4: n=30;
            cout << "April " << year << " has " << n <<" days" ;break;
            case 5: n=31;
            cout << "May " << year << " has " << n <<" days" ;break;
            case 6: n=30;
            cout << "June " << year << " has " << n <<" days" ;break;
            case 7: n=31;
            cout << "July " << year << " has " << n <<" days" ;break;
            case 8: n=31;
            cout << "August " << year << " has " << n <<" days" ;break;
            case 9: n=30;
            cout << "September " << year << " has " << n <<" days" ;break;
            case 10: n=31;
            cout << "October " << year << " has " << n <<" days" ;break;
            case 11: n=30;
            cout << "November " << year << " has " << n <<" days" ;break;
            case 12: n=31;
            cout << "December " << year << " has " << n <<" days"; break;
            }
            }


            6楼2014-11-10 16:15
            回复
              #include <iostream> using namespace std; int n; int sum=0; //数据互换 void swap(int *a,int *b){ int temp; temp=*a; *a=*b; *b=temp; } //输出结果 void result(int a[]){ sum++; cout<<sum<<endl; for(int i=0;i<n;i++){ cout<<a[i]; } cout<<endl; } //实现全排列核心算法 void Perm(int a[],int n){ int i; if(n==1){ result(a); } else{ for(i=0;i<n;i++){ ; Perm(a,n-1); ; } } //主函数 int main(){ int a[101]; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } urn }


              7楼2014-11-24 16:58
              回复
                #include<iostream>
                using namespace std;
                int main()
                {
                double a,b;
                int c,d;
                cin >> a >> b;
                c=1000000*a;
                d=1000000*b;
                if(c==d) cout << "Yes" << endl;
                else cout << "endl" << endl;
                return 0;
                }


                8楼2014-11-24 16:58
                回复
                  #include<iostream>
                  #include<string.h>
                  using namespace std;
                  bool isAnagram(const char * const s1, const char * const s2){
                  char a[100], b[100];
                  int len1, len2;
                  len1 = strlen(s1);
                  len2 = strlen(s2);
                  for(int i= 0; i < 100; i++){
                  a[i] = s1[i];
                  b[i] = s2[i];
                  }
                  if(len1 == len2){
                  for(int j = 0; j < len1-1; j++)
                  for(int k = j; k < len1; k++){
                  if(a[j] > a[k]) swap(a[j], a[k]);
                  if(b[j] > b[k]) swap(b[j], b[k]);
                  }
                  if(strcmp(a, b) == 0) return 1;
                  else return 0;
                  }
                  return 0;
                  }
                  int main(){
                  char x[100], y[100];
                  cin >> x >> y;
                  if(isAnagram) cout << "Yes" << endl;
                  else cout << "No" << endl;
                  }


                  9楼2014-12-22 16:21
                  回复
                    #include<iostream>
                    using namespace std;
                    struct student{
                    int num;
                    int grade;
                    };
                    int main(){
                    int n,m;
                    cin >> n;
                    student stu[100];
                    for(int i =0; i < n; i++){
                    cin >> stu[i].num >> stu[i].grade;
                    }
                    for(int j = 0; j < n-1 ; j++)
                    for(int k = j+1; k < n; k++)
                    if(stu[j].grade < stu[k].grade)
                    swap(stu[j],stu[k]);
                    cin >> m;
                    while(m--){
                    int x, y;
                    cin >> x >> y;
                    if(x == 1){
                    for(int i = 0; i < n; i++)
                    if(stu[i].num == y){
                    cout << stu[i].grade << endl;
                    break;
                    }
                    }
                    if(x == 2){
                    for(int i = 0; i < n; i++)
                    if(stu[i].num == y){
                    cout << i+1 << endl;
                    break;
                    }
                    }
                    if(x == 3){
                    for(int i = 0; i < n; i++)
                    if(stu[i].grade == y){
                    cout << i+1 << endl;
                    break;
                    }
                    }
                    if(x == 4){
                    int count = 0;
                    for(int i = 0; i < n; i++){
                    if(y == stu[i].grade) count++;
                    }
                    cout << count << endl;
                    break;
                    }
                    }
                    }


                    10楼2015-03-16 15:50
                    回复
                      #include<iostream>
                      using namespace std;
                      struct student{
                      int num;
                      int grade;
                      };
                      int main(){
                      int n,m;
                      cin >> n;
                      student stu[100];
                      for(int i =0; i < n; i++){
                      cin >> stu[i].num >> stu[i].grade;
                      }
                      for(int j = 0; j < n-1 ; j++)
                      for(int k = j+1; k < n; k++)
                      if(stu[j].grade < stu[k].grade)
                      swap(stu[j],stu[k]);
                      cin >> m;
                      while(m--){
                      int x, y;
                      cin >> x >> y;
                      if(x == 1){
                      for(int i = 0; i < n; i++)
                      if(stu[i].num == y){
                      cout << stu[i].grade << endl;
                      break;
                      }
                      }
                      if(x == 2){
                      int temp;
                      for(int i = 0; i < n; i++)
                      if(stu[i].num == y)
                      temp = stu[i].grade;
                      for(int i = 0; i < n; i++)
                      if(stu[i].grade == temp) cout << i << endl;
                      break;
                      }
                      if(x == 3){
                      for(int i = 0; i < n; i++)
                      if(stu[i].grade == y){
                      cout << i+1 << endl;
                      break;
                      }
                      }
                      if(x == 4){
                      int count = 0;
                      for(int i = 0; i < n; i++){
                      if(y == stu[i].grade) count++;
                      }
                      cout << count << endl;
                      break;
                      }
                      }
                      }


                      11楼2015-03-16 16:04
                      回复