复杂环境下的数据统计问题
进行数值统计的时候,可能会混入一些非数值的元素,下面请编程完成对输入序列进行求和统计并输出, 如果遇到非数值元素,则自动跳过,并在最终结果输出行之后另起一行,输出attention
输入格式:
单行输入,元素之间使用空格分开
输出格式:
对元素所对应的整数进行求和并输出
如果遇到非数值元素,则自动跳过,并在最终结果输出行之后另起一行,输出attention
输入样例a:
在这里给出一组输入。例如:
1 2 3 4 5
输出样例a:
在这里给出相应的输出。例如:
15
输入样例b:
在这里给出一组输入。例如:
1 2 3 4 a 5
输出样例b:
在这里给出相应的输出。例如:
15
attention
#define debug
#ifdef debug
#include <time.h>
#include "/home/majiao/mb.h"
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <math.h>
#define MAXN ((int)1e5+7)
#define ll long long
#define INF (0x7f7f7f7f)
#define fori(lef, rig) for(int i=lef; i<=rig; i++)
#define forj(lef, rig) for(int j=lef; j<=rig; j++)
#define fork(lef, rig) for(int k=lef; k<=rig; k++)
#define QAQ (0)
using namespace std;
#define show(x...) \
do { \
cout << "\033[31;1m " << #x << " -> "; \
err(x); \
} while (0)
void err() { cout << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
namespace FastIO {
char print_f[105];
void read() { }
void print() { putchar('\n'); }
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth) {
x = 0;
char ch = getchar();
ll f = 1;
while (!isdigit(ch)) {
if (ch == '-') f *= -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
x *= f;
read(oth...);
}
template <typename T, typename... T2>
inline void print(T x, T2... oth) {
ll p3=-1;
if(x<0) putchar('-'), x=-x;
do{
print_f[++p3] = x%10 + 48;
} while(x/=10);
while(p3>=0) putchar(print_f[p3--]);
putchar(' ');
print(oth...);
}
} // namespace FastIO
using FastIO::print;
using FastIO::read;
int n, m, Q, K;
bool NOTNUM(string& s) {
for(auto ch : s)
if(ch>'9' || ch<'0') return true;
return false;
}
int main() {
#ifdef debug
freopen("test", "r", stdin);
// freopen("out_main", "w", stdout);
clock_t stime = clock();
#endif
string str;
int sum = 0, flag = false;
while((cin >> str) && !str.empty()) {
if(NOTNUM(str)) {
// printf("%d\nattention", sum);
flag = true;
} else {
sum += atoi(str.data());
}
}
printf("%d\n%s", sum, flag ? "attention" : "");
#ifdef debug
clock_t etime = clock();
printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif
return 0;
}