Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. // DailyProgrammer_ibeforee.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <fstream>
  7. #include <iostream>
  8. #include <vector>
  9. #include <string>
  10. #pragma warning(disable:4996)
  11. using namespace std;
  12.  
  13.  
  14.  
  15.  
  16.  
  17. int isvalid(string str) {
  18.     //char *string;
  19.     //string = (char*)malloc(100 * sizeof(char));
  20.  
  21.    
  22.     int isvalid = 1;
  23.     int i = 0;
  24.     while (str[i] != '\0') {
  25.         if (str[i] == 'c') {
  26.             if (str[i + 1] != '\0' || str[i + 1] != '\0') {
  27.                 if (str[i + 1] == 'i' && str[i + 2] == 'e') {
  28.                     isvalid = 0;
  29.                 }
  30.             }
  31.  
  32.         }
  33.  
  34.         if (str[i] == 'e' && i == 0) {
  35.  
  36.             if (str[i + 1] == 'i') {
  37.                 isvalid = 0;
  38.             }
  39.  
  40.  
  41.         }
  42.         if (str[i] == 'e' && i != 0) {
  43.             if (str[i - 1] != 'c' && str[i + 1] == 'i') {
  44.                 isvalid = 0;
  45.             }
  46.  
  47.         }
  48.  
  49.         i++;
  50.     }
  51.     return isvalid;
  52. }
  53.  
  54. void ReadScores() {
  55.     std::vector<std::string> words;
  56.     const char * filename = "C:\\enable1.txt";
  57.     std::ifstream myfile;
  58.     std::string name;
  59.     std::string line;
  60.     std::string score;
  61.  
  62.     myfile.open(filename, std::ios::in);
  63.     if (!myfile.is_open()) {
  64.         std::cerr << "Can't open " << filename << "!\n";
  65.     }
  66.     else {
  67.         int a = 0;
  68.         while (myfile >> name >> score) {
  69.             while (std::getline(myfile, line)) {
  70.                 words.push_back(line);
  71.             }
  72.  
  73.             //std::cout << name << "\t" << score << std::endl;
  74.         }
  75.         myfile.close();
  76.        
  77.  
  78.         int j = words.size();
  79.         cout << j << endl;
  80.        
  81.         int total = 0;
  82.         for (int i = 0; i < j; i++) {
  83.             if (isvalid(words[i]) == 1) {
  84.                 total++;
  85.             }
  86.         }
  87.         cout << (j-total) << endl;
  88.        
  89.  
  90.  
  91.  
  92.     }
  93.  
  94. }
  95.  
  96. int main()
  97. {
  98.     ReadScores();
  99.  
  100.     /*char *string;
  101.     string = (char*)malloc(100 * sizeof(char));
  102.  
  103.     printf("Please input a word\n");
  104.     scanf("%s", string);
  105.  
  106.     int isvalid = 1;
  107.     int i = 0;
  108.     while (string[i] != '\0') {
  109.         if (string[i] == 'c') {
  110.             if (string[i + 1] != '\0' ||  string[i + 1] != '\0') {
  111.                 if (string[i + 1] == 'i' && string[i + 2] == 'e') {
  112.                     isvalid = 0;
  113.                 }
  114.             }
  115.            
  116.         }
  117.  
  118.         if (string[i] == 'e' && i == 0) {
  119.  
  120.             if (string[i + 1] == 'i') {
  121.                 isvalid = 0;
  122.             }
  123.  
  124.  
  125.         }      
  126.         if (string[i] == 'e' && i != 0) {
  127.             if (string[i - 1] != 'c' && string[i + 1] == 'i') {
  128.                 isvalid = 0;
  129.             }
  130.        
  131.         }
  132.                
  133.             i++;
  134.         }
  135.  
  136.         printf("%d\n", isvalid);
  137.         */
  138.         return 0;
  139.  
  140.  
  141.  
  142.  
  143.  
  144.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement