东秦图灵杯.平方和和立方和·

来源:互联网 发布:xquartz2.7.5 mac 编辑:程序博客网 时间:2024/06/09 23:20
行输入,一行连续整数。
对其中所有奇数进行立方运算,并求和。
对其中所有偶数进行平方运算,并求和。
输出上述信息。


代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
 vector<int>lisa;
 int s, suma =0,sumb = 0;
 cout << "输入数据,‘#’结尾"<<endl;
 while (cin >> s)
  lisa.push_back(s);
 auto a = lisa.begin();
 auto b = lisa.end();
 while (a!=b)
 {
  if (*a % 2 == 0)
   suma += (*a)*(*a);
  else sumb += (*a)*(*a)*(*a);
  ++a;
 }
 if (cout << "偶数平方和:" << suma << endl << "奇数立方和:" << sumb << endl)
  cout << "m_geek 你最帅!" << endl;
 else cout << "呸!m_geek 你个臭屌丝!" << endl;
 system("pause");
 return 0;
}
运行结果:
原创粉丝点击