zoukankan      html  css  js  c++  java
  • ACM Steps_Chapter One_Section2

    Elevator

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n,temp,last=0,sum,N;
    	while(cin>>n,n!=0)
    	{
    		sum=0;
    		last=0;
    		N=n;
    		while(n--)
    		{
    			cin>>temp;
    			if(temp>last)
    			{
    				sum+=(temp-last)*6;
    				last=temp;
    			}
    			else 
    			{
    				sum+=(last-temp)*4;
    				last=temp;
    			}
    		}
    		cout<<sum+5*N<<endl;
    	}
    	system("pause");
    	return 0;
    }
    			
    

    A+B Coming

    #include<iostream>
    using namespace std;
    int main()
    {
    	int a,b;
    	while(cin>>hex>>a>>hex>>b)
    		cout<<a+b<<endl;
    	return 0;
    }
    

    hide handkerchief

    #include<iostream>
    using namespace std;
    int gcd(int m,int n)
    {
    	int r;
    	while(r=m%n)
    	{
    		m=n;
    		n=r;
    	}
    	return n;
    }
    int main()
    {
    	int n,m;
    	while(cin>>n>>m,n!=-1||m!=-1)
    	{
    		if(gcd(m,n)==1)
    			cout<<"YES"<<endl;
    		else
    			cout<<"POOR Haha"<<endl;
    	}
    	system("pause");
    	return 0;
    }
    

    Buildings

    #include<iostream>
    using namespace std;
    int main()
    {
    	int T;
    	int m,n;
    	int sum=0,temp;
    	int N;
    	cin>>T;
    	while(T--)
    	{
    		cin>>n>>m;
    		N=n*m;
    		while(N--)
    		{
    			cin>>temp;
    			sum+=temp==1?1:0;
    		}
    		cout<<sum<<endl;
    		sum=0;
    	}
    	system("pause");
    	return 0;
    }
    

    decimal system

    #include<iostream>
    using namespace std;
    int main()
    {
        char ch[100];
        int i,j,k,n,a,b;
        int sum;
        while(scanf("%d",&n)!=EOF)
        {
            sum=0;
            for(i=0;i<n;i++)
            {
                scanf("%s",&ch);
                a=0;
                b=0;
                for(j=0;ch[j]!='(';j++)
    				;
                for(k=j+1;ch[k]!=')';k++)
                    b=b*10+(ch[k]-'0');
                for(j=0;ch[j]!='(';j++)
                    a=a*b+(ch[j]-'0');
                sum+=a;
            }
            printf("%d\n",sum);
        }
        return 0;
    }
    

    Lowest Bit

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n;
    	int ans=1;
    	while(cin>>n,n!=0)
    	{
    		while(n%2!=1)
    		{
    			n/=2;
    			ans*=2;
    		}
    		cout<<ans<<endl;
    		ans=1;
    	}
    	system("pause");
    	return 0;
    }
    

    Specialized Four-Digit Numbers

    #include<iostream>
    int  fun(int n,int m)
    {
    	int a = n/(m*m*m);
    	int b = (n-a*m*m*m)/(m*m);
    	int c = (n-a*m*m*m-b*m*m)/m;
    	int d = n-a*m*m*m-b*m*m-c*m;
    	return a+b+c+d;
    }
    using namespace std;
    int main()
    {
    	int n;
    	for(n=2992;n<=9999;n++)
    	{
    		if((fun(n,10)==fun(n,12))&&(fun(n,10)==fun(n,16)))
    			cout<<n<<endl;
    	}
    	system("pause");
    	return 0;
    }
    		
    

    AC Me

    #include<iostream>
    #include<cstdio>
    #include<string>
    using namespace std;
    int main()
    {
    	int a[26],i,j,x;
    	char str[100001];
        while(gets(str))
    	{   
    		x=strlen(str);
         	int a[26]={0};
       		for(i=0;i<x;i++)
       		{   
    			if(str[i]>='a'&&str[i]<='z')   
        			a[str[i]-'a']++;
    		}
       		for(i=0;i<26;i++)
       			printf("%c:%d\n",i+'a',a[i]);
         	printf("\n");
    
    	}
    	return 0;
    }
    


  • 相关阅读:
    Linux 防火墙配置
    【存在问题,待修改】SSH 远程登陆
    Hadoop 本地模式安装
    CentOS7 安装 JDK
    JS的DOM操作
    JavaScript
    格式与布局(定位)
    样式表
    表单、内嵌网页
    HTML中的一般标签、常用标签和表格
  • 原文地址:https://www.cnblogs.com/oldoldb/p/3311327.html
Copyright © 2011-2022 走看看