#P1839. 程序阅读题.3
程序阅读题.3
1. 第一题
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
int first=true;
for(int i=2;n!=1;i++)
{
while(n%i==0)
{
if(first)
{
cout<<i;
first = false;
}
else
cout<<","<<i;
n = n/i;
}
}
return 0;
}
运行程序,输入: 504
程序输出:{{ input(1) }}
2. 第二题
#include<bits/stdc++.h>
using namespace std;
int n,f[101];
int main()
{
cin>>n;
while(n--)
{
int t;
cin>>t;
f[t]++;
}
int max,cnt,num;
max=cnt=0;
for(int i=1;i<=100;i++)
{
if(f[i]==0) continue;
cnt++;
if(f[i]>max)
{
max = f[i];
num = i;
}
}
cout<<cnt<<" "<<num<<" "<<max;
return 0;
}
运行程序,输入:
15
9 13 5 7 9 5 3 5 15 21 9 2 6 11 11
程序输出:{{ input(2) }}
3. 第三题
#include<bits/stdc++.h>
using namespace std;
int n,x[101];
int main()
{
cin>>n;
int cnt=0,len=0;
for(int i=1;i<=n;i++)
{
cin>>x[i];
if(x[i]>x[i-1])
len ++;
else
len = 1;
if(len==3)
cnt++;
}
cout<<cnt;
return 0;
}
运行程序,输入:
15
1 5 3 6 8 10 11 2 3 1 5 7 8 9 11
程序输出:{{ input(3) }}
4. 第四题
#include<bits/stdc++.h>
using namespace std;
int n,x[101];
int main()
{
cin>>n;
int cnt=0,len=0;
for(int i=1;i<=n;i++)
cin>>x[i];
for(int i=1,j=n;i<j;i++,j--)
{
if(x[i]>x[j])
{
int t;
t = x[i];
x[i] = x[j];
x[j] = t;
}
}
for(int i=1;i<=n;i++)
cout<<x[i]<<" ";
return 0;
}
运行程序,输入:
9
1 14 9 13 2 8 11 4 5
程序输出:{{ input(4) }}
5. 第五题
#include<bits/stdc++.h>
using namespace std;
int n,x[101];
int main()
{
cin>>n;
int sum=0,cnt=1;
for(int i=1;i<=n;i++)
{
cin>>x[i];
if(sum+x[i]>10)
{
cnt++;
sum = x[i];
cout<<endl<<x[i]<<" ";
}
else
{
sum += x[i];
cout<<x[i]<<" ";
}
}
cout<<endl<<cnt;
return 0;
}
运行程序,输入内容为:
10
5 3 2 1 6 4 2 1 1 1
程序输出的第一行内容为:{{ input(5) }}
程序输出的第一行内容为:{{ input(6) }}
程序输出的第一行内容为:{{ input(7) }}
程序输出的第一行内容为:{{ input(8) }}