- #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;
- }
少儿编程答疑, 算法答疑请加微信 307591841 或 QQ307591841
公众号. jpg
来源: http://www.jianshu.com/p/6b9ee769ba01