ACM集训一
NEFU 1064
B题:(矩阵外围数字之和)
Problem:B
Time Limit:1000ms
Memory Limit:65536K
Description
在军事训练中,战士们站成一个方阵(也可能是一个长方形),每个战士身上都有1个编号,现在军队领导想知道,站在队伍外围战士们的编号之和是多少?大一的你能帮帮他吗? 本题20分
Input
输入数据有多组,每组第一行n和m(1<n,m<=10),代表行数和列数。接下来是n行m列个战士的编号值value[i],0<= value[i] <=100;
Output
在一行内输出外围战士的编号之和。
Sample Input
3 3
1 2 3
4 5 6
0 1 0
Sample Output
17
题解:c++
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[200][200],m,n,s;
while(scanf("%d%d",&n,&m)!=-1)
{
s=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==1||i==n||j==1||j==m)
{
s=s+a[i][j];
}
}
}
printf("%d\n",s);
}
return 0;
}
NEFU 1031
D题:
回转小矩阵(二维数组逆时针旋转90度)
Problem:D
Time Limit:1000ms
Memory Limit:65536K
Description
现在有一个n*m行的矩阵A 逆时针旋转90度形成一个新的矩阵B,将B矩阵输出来。
快敲代码,动作!
Input
多组样例,每行两个整数n,m( 1<=n<=100, 1<=m<=100 )
Output
输出矩阵B
Sample Input
3 5
1 2 3 4 5
2 4 9 2 1
3 4 5 7 9
Sample Output
5 1 9
4 2 7
3 9 5
2 4 4
1 2 3
题解:c++
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[200][200],b[200][200],m,n,s;
while(scanf("%d%d",&n,&m)!=-1)
{
s=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
b[m-j+1][i]=a[i][j];
}
}
for(int i=1;i<=m;i++)
{
for(int j=1;j<n;j++)
{
printf("%d ",b[i][j]);
}
printf("%d",b[i][n]);
printf("\n");
}
}
return 0;
}
J 谁不及格?NEFU1147
谁不及格?
Problem:1147
Time Limit:1000ms
Memory Limit:65535K
Description
聪聪的班主任王老师最近有点忙,可是他又是一位非常细心的老师,每次考试成绩都有专门的东西来记录,学期结束的时候给每位学生算了加权之后,他都要“关心关心”成绩不好的学生,并在假期给他们补补功课。什么是成绩不好呢?在王老师眼里,成绩不好当然就是加权成绩不及格咯!如今王老师这么忙,正好看你成天写程序闲着没事儿,于是他想让聪明的你来帮他写个程序,把那些不及格的同学的名单打印给他。
Input
输入包含多组数据,每组输入一个数n(1<=n<=10),然后接下来输入n个同学的信息,每个同学的信息分3行,第一行姓名name(姓名长度不超过20个字母),第二行学号x,长度为10(例:2015215098),第三行学生的平均加权成绩。
Output
每组数据第一行输出一个数k,表示不及格学生的个数,然后接下来输出3*k行不及格学生信息,第一个k行输出不及格学生姓名(按输入顺序),第二个k行输出学生学号(按输入顺序),第三个k行输出学生成绩(按输入顺序)(保留2位小数)。若是没有同学不及格,那么输出“They are Great!!”。
Sample Input
2
zhu dan
2015213678
79.99
wang meng
2015213902
83.78
1
tiancai
2015234930
59.08
Sample Output
They are Great!!
1
tiancai
2015234930
59.08
#include <bits/stdc++.h>
using namespace std;
struct student{
char xh[100];
double cj;
char name[100];
};
int main()
{
int n,k;
student s[10];
char name[100];
while (cin>>n)
{
k=0;
for(int i=0;i<n;i++)
{
**getchar();
gets(s[i].name);**(因为名字带了空格,不能直接cin,要用gets)
cin>>s[i].xh>>s[i].cj;
if(s[i].cj<60)
k++;
}
if(k)
{
cout<<k<<endl;
for(int i=0;i<n;i++)
{
if(s[i].cj<60)
{
cout<<s[i].name<<endl;
}
}
for(int i=0;i<n;i++)
{
if(s[i].cj<60)
{
cout<<s[i].xh<<endl;
}
}
for(int i=0;i<n;i++)
{
if(s[i].cj<60)
{
printf("%.2lf\n",s[i].cj);
}
}
}
else
{
cout<<"They are Great!!"<<endl;
}
}
return 0;
}