求其最大公约数和最小公倍数
时间: 1ms 内存:128M
描述:
输入两个正整数m和n,求其最大公约数和最小公倍数。
输入:
两个整数
输出:
最大公约数,最小公倍数
示例输入:
5 7
示例输出:
1 35
提示:
参考答案(内存最优[0]):
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
char c;
int letters=0,space=0,digit=0,other=0;
cout<<"enter one line:";
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else other++;
}
cout<<"letters:"<<letters<<" "<<"space:"<<space<<" "<<"digit:"<<digit<<" "<<"other:"<<other<<endl;
return 0;
}
参考答案(时间最优[0]):
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
char c;
int letters=0,space=0,digit=0,other=0;
cout<<"enter one line:";
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else other++;
}
cout<<"letters:"<<letters<<" "<<"space:"<<space<<" "<<"digit:"<<digit<<" "<<"other:"<<other<<endl;
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。