VMTEST - Thử máy

Tác giả: RR

Ngôn ngữ: C++

//#pragma comment(linker, "/STACK:66777216")
#include <iomanip>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>
#include <bitset>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define DEBUG(x) cout << #x << " = " << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(i,1,n) cout << a[i] << ' '; puts("");
#define PR0(a,n) cout << #a << " = "; REP(i,n) cout << a[i] << ' '; puts("");
using namespace std;

const double PI = acos(-1.0);

char s[100111];

bool allNum() {
    REP(i,strlen(s))
    if (s[i] != ' ')
    if (s[i] != '-' && s[i] != '.')
        if (s[i] < '0' || s[i] > '9') return false;
    return true;
}

bool allChar() {
    REP(i,strlen(s))
    if (s[i] != ' ')
    if (s[i] < 'a' || s[i] > 'z')
    if (s[i] < 'A' || s[i] > 'Z') return false;
    return true;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    while (gets(s)) {
        if (s[0] == '?') break;
        if (allNum()) {
            istringstream sin(s);
            long double res = 0.0, x;
            while (sin >> x) {
                res += x;
            }
            cout << (fixed) << setprecision(6) << res << endl;
        }
        else if (allChar()) {
            istringstream sin(s);
            string res = "", x;
            while (sin >> x) {
                res += x;
            }
            cout << res << endl;
        }
        else puts("Error!");
    }
    return 0;
}

Download