View Code of Problem 120

#include<iostream>
#include<cmath>
#include <string>
using namespace std;
struct time
{
	int hour;
	int min;
};
bool can(int a) {
	int flag = 1;
	if (a == 0||a==1)return 0;
	for (int i = 2; i < sqrt(a)+1; i++)
	{
		if (a % i == 0) {
			flag = 0;
			break;
		}
	}
	return flag;
}
int main() {
	string a, b;
	while (cin >> a) {
		cin >> b;
		int court = 0;
		time bg, end;
		bg.hour = stoi(a.substr(0, 2));
		bg.min = stoi(a.substr(3, 5));
		end.hour = stoi(b.substr(0, 2));
		end.min = stoi(b.substr(3, 5));
		int j = bg.min;
		for (int i = bg.hour; i <= end.hour; i++)
		{
			for (; j < 60; j++)
			{
				if (i == end.hour && j > end.min) {
					break;
				}
				if (can(i * 2500 + j)) {
					court++;
				}
			}
			j = 0;
		}
		cout << court << endl;
	}
}
/*
Main.cc: In function 'int main()':
Main.cc:27:7: error: expected ';' before 'bg'
   time bg, end;
       ^~~
       ;
Main.cc:27:15: warning: statement is a reference, not call, to function 'time' [-Waddress]
   time bg, end;
               ^
Main.cc:27:15: warning: statement has no effect [-Wunused-value]
Main.cc:28:3: error: 'bg' was not declared in this scope
   bg.hour = stoi(a.substr(0, 2));
   ^~
Main.cc:28:3: note: suggested alternative: 'b'
   bg.hour = stoi(a.substr(0, 2));
   ^~
   b
Main.cc:30:7: error: overloaded function with no contextual type information
   end.hour = stoi(b.substr(0, 2));
       ^~~~
Main.cc:31:7: error: overloaded function with no contextual type information
   end.min = stoi(b.substr(3, 5));
       ^~~
Main.cc:33:34: error: overloaded function with no contextual type information
   for (int i = bg.hour; i <= end.hour; i++)
                                  ^~~~
Main.cc:37:18: error: overloaded function with no contextual type information
     if (i == end.hour && j > end.min) {
                  ^~~~
Main.cc:37:34: error: overloaded function with no contextual type information
     if (i == end.hour && j > end.min) {
                                  ^~~
*/

Double click to view unformatted code.


Back to problem 120