统计字符串—公约公倍数—计负均正

//东北大学秦皇岛oj刷题ing
//[http://oj.acmclub.cn/problem.php?id=1007](http://oj.acmclub.cn/problem.php?id=1007)
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a[20],count=0,ans=0;
    for(int i=0;i<20;i++)
    {
      scanf("%d",&a[i]);
      if(a[i]<0)
         count++;
     else
         ans+=a[i]; 
}
printf("%d\n",count);
printf("%.2f",(float)ans/(20-count));
    return 0;
 } 
//其实我最讨厌,公约公倍数啥的了=.=
//[http://oj.acmclub.cn/problem.php?id=1008](http://oj.acmclub.cn/problem.php?id=1008)
#include<iostream>
#include<stdio.h>
using namespace std;
//最大公约数(欧几里得算法—迭代法(递推法)) 
int gcd(int m,int n)
{
    while(m>0)
    {
        int c=n%m;
        n=m;
        m=c;
    }
    return n;
}
//还有一种写法是 只有一句return (m==0)?n:gcd(n%m,m);

// 最小公倍数
long lcm(int x,int y)
{
    return (x*y)/gcd(x,y);
    //最小公倍数=两数的乘积/最大公约数,所以可在最大公约数的基础上求最小公倍数 
}

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    cout<<gcd(a,b)<<endl<<lcm(a,b)<<endl;
    return 0;
 } 
//统计字符,考虑到空格的问题 
//[1009-统计字符](http://oj.acmclub.cn/problem.php?id=1009)
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int count,blank,num,other;
    count=blank=num=other=0;
    char e;
    while((e=getchar())!='\n')
    {
        if((e>='a'&&e<='z')||(e>='A'&&e<='Z'))
            count++;
        else if(e==' ')
            blank++;
        else if(e>='0'&&e<='9')
            num++;
        else{
             other++;   
        }

     } 
     printf("%d\n%d\n%d\n%d\n",count,blank,num,other);
     return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值