0
点赞
收藏
分享

微信扫一扫

2010北京市小学生程序设计友谊赛详细答案

左小米z 2022-08-04 阅读 64


第1题

#include <iostream>
using namespace std;

int main()
{
int a, b;
cin >> a >> b;
cout << a * b << endl;

return 0;
}

第2题

分析:
以下面的数据为例:

3 
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3

对应关系:

班级编号

总力量

1班

5

2班

10

3班

15

按总力量排序后

班级编号

总力量

3班

15

2班

10

1班

5

1班,位于第3行,所以是第3名;2班位于第2行,所以是第2名;3班,位于第1行,所以是第1名。输出结果为3 2 1。

#include <iostream>
using namespace std;

int main()
{
int n;
cin >> n;
int a, b, c, d, e;
int total[11], classNo[11];//总力量和班级编号
for(int i = 1; i <= n; i++)
{
cin >> a >> b >> c >> d >> e;
total[i] = a + b + c + d + e;
classNo[i] = i;
}

for(int i = 1; i < n; i++)
{
for(int j = i + 1; j <= n; j++)
{
if(total[i] < total[j])
{
swap(total[i], total[j]);
swap(classNo[i], classNo[j]);
}
}
}

for(int cls = 1; cls <= n; cls++)
{
for(int row = 1; row <= n; row++)
{
//第row行的班级编程是cls
if(classNo[row] == cls)
{
cout << row << ' ';
}
}
}
cout << endl;

return 0;
}

第3题

#include <iostream>
using namespace std;

int main()
{
string s[10], t;
string tmp;
int pos = 0;

do
{
cin >> tmp;
s[pos] = tmp;
pos++;
}while('.' != tmp[tmp.size() - 1]);

cin >> t;
int cnt = 0;
for(int i = 0; i < pos; i++)
{
if(t ==s[i])
{
cnt++;
}
}

cout << cnt << endl;

return 0;
}



举报

相关推荐

0 条评论