浙江工业大学信息学院之江学院程序设计大赛选拔人员题

本文提供了一系列C++编程练习题目,包括计算整数对的差值、求平均数、绘制长方形等内容,适合初学者实践并提高编程技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


//1000
/*
A-B
输入一些整数对,求其两两之差。
样本输入:
6 3
123 567
样本输出:
3
-444
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
 int a,b;
 while(cin>>a>>b)
  cout<<a-b<<endl;
}

//1001
/*
求平均数
输入一些整数,求其平均值,结果保留3位小数。
样本输入:
2 4 6 8 11 15
样本输出:
7.667
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int sum=0,a,n=0;
  while(cin>>a)
  {
   sum+=a;
   n++;
  }
  printf("%.3f/n",((float)sum)/n);
}


//1002
/*
画长方形
输入一组数据,内含1个字母和二个数字,字母表示长方形的内容,二个整数表示长方形的高和宽,输出该长方形。
样本输入:
M  5  9
样本输出:
MMMMMMMMM
MMMMMMMMM
MMMMMMMMM
MMMMMMMMM
MMMMMMMMM
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
 char m;
 int a,b;
 while(cin>>m>>a>>b)
 {
  for(int i=0;i<a;i++)
  {
   for(int j=0;j<b;j++)
    cout<<m;
   cout<<endl;
  }
 }
}


//1003
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
 char m;
 int a,b;
 char s;
 while(cin>>m>>a>>b)
 {
  int c=0;
  for(int i=0;i<a;i++)
   for(int j=0;j<b;j++)
   {
    cin>>s;
    if(s==m)
     c++;
   }
  cout<<c<<endl;
 }
}


//1004
/*
数特定字符
输入若干个矩阵,输出每个矩阵中的特定字符数。
每个矩阵以一个特定字符和两个整数M、N引导,后跟M行N列字符,统计出矩阵中特定字符的个数。
样本输入:
A 2 3
Xaj
AAi
* 5 9
udfs*%%*R
dfg*8****
sad*****)
y*h**d*$$
assdcjfl*
样本输出:
2
17
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct node{
 int a;
 int b;
 int c;
};

int comp(node a,node b)
{
 if(a.a<b.a)
  return 1;
 else if(a.a==b.a)
 {
  if(a.b<b.b)
   return 1;
  else if(a.b==b.b)
  {
   if(a.c<b.c)
    return 1;
   else return 0;
  }
  else return 0;
 }
 else return 0; 
}

int main()
{
 vector <node> y;
 int a,b,c;
 while(scanf("%d-%d-%d",&a,&b,&c)!=-1)
 {
  node t;
  t.a=a;
  t.b=b;
  t.c=c;
  y.push_back(t);
 }
 sort(y.begin(),y.end(),comp);
 for(int i=0;i<y.size();i++)
 {
  cout<<y[i].a<<"-";
  if(y[i].b<10)
   cout<<0;
  cout<<y[i].b<<"-";
  if(y[i].c<10)
  cout<<0;
  cout<<y[i].c<<endl;
 }
}

 

//1005
/*
日期排序
输入若干个日期,日期以YYYY-MM-DD的年月日格式,请把日期按从小到大的顺序输出。
样本输入:
2003-06-21
2001-12-12
1978-01-31
1999-12-31
样本输出:
1978-01-31
1999-12-31
2001-12-12
2003-06-21
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct node{
 int a;
 int b;
 double s;
};

int comp(node a,node b)
{
 if(a.s<b.s)
  return 1;
 else return 0;
}


int main()
{
 int a,b,t1,t2;
 node t;
 vector<node>s;
 cin>>t1>>t2;
 while(cin>>a>>b)
 {
  t.a=a;
  t.b=b;
  t.s=(a-t1)*(a-t1)+(b-t2)*(b-t2);
  s.push_back(t);
 }
 sort(s.begin(),s.end(),comp);
 cout<<s[0].a<<" "<<s[0].b<<endl;
}

 

//1006
/*
求最短距离的点
输入一些整数对,它们表示一些平面上的坐标点,其中第一个为确定的一个点,求所有后面的那些点到该点最短距离的点。
样本输入:
9 2
1 0
1 1
0 0
1 2
2 1
样本输出:
2 1
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
 int a,b,c;
 while(cin>>a>>b>>c)
 {
  int y=a;
  for(int i=0;i<b-1;i++)
  {
   y=(y%c)*a;
  }
  y=y%c;
  cout<<y<<endl;
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值