---
# System prepended metadata

title: UVa Online Judge 11743 - Credit Check
tags: [UVa, C++]

---

# UVa Online Judge 11743 - Credit Check
[11743 - Credit Check](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2843)

## Solution
```cpp=
/**
*** UVa_Q11743_Credit_Check
***
*** Author: R-CO
*** Mail: daniel1820kobe@gmail.com
*** Date: 2015-09-03
**/
#include <cstdlib>
#include <cstdio>

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
  string numLines;
  string buffer;
  string creditNumber;
  int doubleDigit[8];
  int digit[8];
  size_t index, indexDoubleDigit, indexDigit;
  int sum, sumOfDoubleDigit, sumOfDigit;
  const char validString[] = "Valid";
  const char invalidString[] = "Invalid";

  cin.sync_with_stdio(false);
  
  getline(cin, numLines);
  while (getline(cin, buffer)) {
    sum = 0;
    sumOfDigit = 0;
    sumOfDoubleDigit = 0;
    creditNumber.clear();
    for (index = 0; index < buffer.size(); ++index) {
      if (buffer[index] != ' ') {
        creditNumber += buffer[index];
      }
    }
    for (index = 0, indexDoubleDigit = 0, indexDigit = 0; index < creditNumber.size(); ++index) {
      if ((index & 0x1) == 0) { // index is even
        doubleDigit[indexDoubleDigit] = creditNumber[index] - '0';
        ++indexDoubleDigit;
      }
      else { // index is odd
        digit[indexDigit] = creditNumber[index] - '0';
        ++indexDigit;
      }
    }
    for (index = 0; index < 8; ++index) {
      doubleDigit[index] <<= 1;
      if (doubleDigit[index] >= 10) {
        sumOfDoubleDigit += doubleDigit[index] - 9; // sumOfDoubleDigit += doubleDigit[index] - 10 + 1;
      }
      else {
        sumOfDoubleDigit += doubleDigit[index];
      }
      sumOfDigit += digit[index];
    }
    sum = sumOfDoubleDigit + sumOfDigit;
    if ((sum % 10) == 0) {
      printf("%s\n", validString);
    }
    else {
      printf("%s\n", invalidString);
    }
  }
  
  return EXIT_SUCCESS;
}

```



---


## Result
![](https://i.imgur.com/OZErzvW.png)

###### tags: `UVa` `C++`