zoukankan      html  css  js  c++  java
  • 入门手把手教学代码

    题目网站: http://acm.hdu.edu.cn/listproblem.php?vol=11

    输入输出的对比:

        int x; char x;double x;cin>>x;
        int x; scanf("%d",&x); printf("%d
    ",x);
        char c; scanf("%c",&c); printf("%c",c);
        double x; scanf("%lf",&x); printf("%lf",x);

    HDU2000:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        char a,b,c;
        while(cin>>a>>b>>c){
           if(a>b) swap(a,b);
           if(b>c) swap(b,c);
           if(a>b) swap(a,b);
           cout<<a<<" "<<b<<" "<<c<<endl; 
        }
        return 0;
    }
    C语言版本:
    #include<bits/stdc++.h> using namespace std; int main() { char a,b,c; while(~scanf("%c%c%c ",&a,&b,&c)){ //过滤换行符 if(a>b) swap(a,b); if(b>c) swap(b,c); if(a>b) swap(a,b); printf("%c %c %c ",a,b,c); } return 0; }

    HDU2001:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double x1,x2,y,y2,ans;
        while(cin>>x1>>y>>x2>>y2){
            ans=sqrt((x1-x2)*(x1-x2)+(y-y2)*(y-y2));
            printf("%.2lf
    ",ans);
        }
        return 0;
    }

    HDU1001:

     #include<bits/stdc++.h>
    using namespace std;
    int main()
    { 
        long long ans,n;
        while(cin>>n)
        {
            ans=(1+n)*n/2;
            cout<<ans<<endl;
            cout<<endl;
        }
        return 0;
    }

    HDU2002:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double r,pi=3.1415927; //int double
        while(cin>>r){
            printf("%.3lf
    ",4.0/3*pi*r*r*r);
        }
        return 0;
    }

    HDU2003:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double N;
        while(cin>>N)
        {
            if(N>0) printf("%.2lf
    ",N);
            else printf("%.2lf
    ",-N);
        }
        return 0;
    }

     HDU2010:

    非函数版本
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int L,R;
        while(cin>>L>>R){
            int i,cnt=0;
            for(int i=L;i<=R;i++){
                int a=i/100;
                int b=(i-a*100)/10;
                int c=i%10;
                if(a*a*a+b*b*b+c*c*c==i){
                    if(cnt==0) cout<<i;
                    else cout<<" "<<i;
                    cnt++;
                }
            }
            if(cnt==0) cout<<"no";
            cout<<endl;
        }
        return 0;
    }
    函数版本
    #include<bits/stdc++.h> using namespace std; bool check(int x) { //356%10=6; 356/10=35; int a=x/100; int b=(x-a*100)/10; int c=x%10; if(pow(a,3)+pow(b,3)+pow(c,3)==x) return true; else return false; } int main() { int i,L,R; //3 4 5 6 while(cin>>L>>R){ int cnt=0; for(int i=L;i<=R;i++){ if(check(i)==true){ if(cnt==0) cout<<i; else cout<<" "<<i; cnt++; } } if(cnt==0) cout<<"no"; printf(" "); } return 0; }

     2008:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int N; double x;
        while(cin>>N){
           if(N==0) break;
           int a=0,b=0,c=0;
           for(int i=1;i<=N;i++){
               cin>>x;
               if(x<0) a++;
               else if(x==0) b++;
               else c++;
           }
           cout<<a<<" "<<b<<" "<<c<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SQL语句在数据库中可以执行在mybatis执行不了
    spring_08aop原理及案例
    spring_07使用spring的特殊bean、完成分散配置
    spring_06装配bean_2
    spring_05装配bean
    spring_03ApplicationContext三种经常用到的实现
    spring_04bean的生命周期
    spring_02工具及接口案例
    深入理解Ribbon之源码解析
    深入理解Feign之源码解析
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9837027.html
Copyright © 2011-2022 走看看