目录
题目一:
题目二:
题目三:
题目四:
题目一:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cin>>n;
int a[100];//装因子
int p = 0;//递增数组序号
for(int i=2;i<sqrt(n)+1;i++)
{
if(n%i==0)
a[p++]=i;
}
if(p==0)//是素数
a[p++]=n;
int sum=1;//乘积和
int cnt=1;//因子个数
int maxx=1;//记录最长连续因子数
int yy=0;//记录最长连续因子序列的第一个数下标
for(int i=0;i<p;i++)
{
sum = a[i];
cnt=1;
for(int j=i+1;j<p;j++)
{
if(a[j]==a[j-1]+1)//符合连续
{
sum=sum*a[j];
if(n%sum==0)//相乘是否还是n的因子
{
cnt++;
if(cnt>maxx)
{
maxx=cnt;
yy=i;
}
}
else
{
break;//退出
}
}
else
{
break;
}
}
}
cout<<maxx<<endl;
for(int i=yy;i<yy+maxx;i++)
{
cout<<a[i];
if(i!=yy+maxx-1)
cout<<"*";
}
cout<<endl;
}
题目二:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;
int main()
{
int n, a, b, sum_a=0, sum_b = 1, t;
cin >> n;
for (int i = 0; i < n; i++)
{
scanf("%d/%d", &a, &b);
sum_a *= b;//sum_a 分子
sum_a += a * sum_b;//sum_b 分母
sum_b *= b;
//cout << sum_a << " " << sum_b << endl;
t = __gcd(sum_a, sum_b);//最大公约数
//cout << t << endl;
sum_a /= t;//约分
sum_b /= t;
}
if (sum_a % sum_b == 0)
cout << sum_a / sum_b << endl;
else if (sum_a < sum_b)
cout << sum_a << "/" << sum_b << endl;
else
cout << sum_a / sum_b << " " << sum_a % sum_b << "/" << sum_b << endl;
}
题目三:
#include<iostream>
#include<cstring>
using namespace std;
int a[1100];
int main()
{
int n;
cin>>n;
memset(a,0,sizeof(a));
while(n--)
{
int k;
cin>>k;
while(k--)
{
int x;
cin>>x;
a[x]+=1;
}
}
int flag,maxflag=0;
for(int i=1;i<=1000;i++)
{
if(maxflag<=a[i])
{
flag=i;
maxflag=a[i];
}
}
cout<<flag<<" "<<maxflag<<endl;
}
题目四:
#include<iostream>
using namespace std;
int main()
{
string s;
string name2,name14;
int cnt=0;
while(cin>>s)
{
if(s==".")
break;
cnt++;
if(cnt==2)
name2=s;
if(cnt==14)
name14=s;
}
if(cnt<2)
cout<<"Momo... No one is for you ..."<<endl;
else if(cnt>=2&&cnt<14)
cout<<name2<<" is the only one for you..."<<endl;
else if(cnt>=14)
cout<<name2<<" and "<<name14<<" are inviting you to dinner..."<<endl;
}