Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh-jsh authored Mar 15, 2022
1 parent 2fc63d3 commit 1926f8d
Show file tree
Hide file tree
Showing 2 changed files with 293 additions and 0 deletions.
246 changes: 246 additions & 0 deletions WCH.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/*
Web-Class-Helper v1.0.0
JSH
*/
//#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <sstream>
#include <bits/stdc++.h>
#include "WCH.h"
using namespace std;
struct TalkDate{
int Year;
int Month;
int Day;
int Hour;
int Minute;
int Second;
string Name;
};
multimap<int,pair<int,string> > mm;
TalkDate GetTime();
void PrintTime(TalkDate);
void PrintError();
void PrintOK();
void Bye();
inline void in_data(string);
inline void out_data(string);
void HideWindow(bool);
bool JudgeKey();
void Game();
string op;
string Weekdayname[7] = {
"Sunday.txt",
"Monday.txt",
"Tuesday.txt",
"Wednesday.txt"
"Thursday.txt",
"Friday.txt",
"Saturday.txt"};
int n;
bool fgh=1;
ifstream fin;
ofstream fout;
int main(){
system("mode con cols=50 lines=5");
SetConsoleTitle("Web-Class-Helper");
TalkDate q=GetTime();
if (q.Month == 1 || q.Month == 2)
{
q.Month += 12;
q.Year--;
}
int Week = (q.Day + 2 * q.Month + 3 * (q.Month + 1) / 5 + q.Year + q.Year / 4 - q.Year / 100 + q.Year / 400+1) % 7;
HideWindow(1);
fin.open(Weekdayname[Week].c_str());
fin>>n;
for(int i=1;i<=n;i++){
int h=0;
int m=0;
string tname="NULL";
fin>>h>>m>>tname;
mm.emplace(make_pair(h,make_pair(m,tname)));
//cout<<mm.count(h)<<endl;
}
printf("Please input your name:");
cin >> op;
printf("Welcome\n");
while(op!="bye"){
int h=GetTime().Hour;
for (auto it = mm.equal_range(h).first; it != mm.equal_range(h).second; it++)
{
if ((it->second).first == GetTime().Minute && ((it->second).second).size() > 0)
{
printf("\a");
MessageBox(NULL, ((it->second).second).c_str(), "Web-Class-Helper", MB_OK);
}
}
if(op=="add"){
int h=0;
int m=0;
string tname="NULL";
scanf("%d%d",&h,&m);
cin>>tname;
if(h>24||m>=60||h<1||m<0){
PrintError();
}
else{
n++;
mm.emplace(make_pair(h, make_pair(m, tname)));
PrintOK();
}
}
if(op=="delete"){
int h=0;
int m=0;
int flag=0;
string tname="NULL";
scanf("%d%d",&h,&m);
cin>>tname;
for (auto it = mm.equal_range(h).first; it != mm.equal_range(h).second; it++)
{
if ((it->second).first == m && ((it->second).second) == tname)
{
mm.erase(it);
PrintOK();
flag=1;
n--;
}
}
if(!flag){
PrintError();
}
}
if(op=="change"){
int h = 0;
int m = 0;
int flag = 0;
string tname = "NULL";
scanf("%d%d", &h, &m);
cin >> tname;
for (auto it = mm.equal_range(h).first; it != mm.equal_range(h).second; it++)
{
if ((it->second).first == m)
{
((it->second).second) = tname;
PrintOK();
flag = 1;
}
}
if (!flag)
{
PrintError();
}
}
if(op=="ow"){
GetGet();
}
if(JudgeKey()){
HideWindow(1);
fgh=1;
}
if (fgh == 1)
{
cin >> op;
}
if(op=="hide"){
HideWindow(0);
fgh=0;
}
if(op=="game"){
Game();
}
if(op=="time"){
PrintTime(GetTime());
}
}
fout.open(Weekdayname[Week].c_str());
fout<<n<<endl;
for(auto it=mm.begin();it!=mm.end();it++){
fout<<(it->first)<<" "<<(it->second).first<<" "<<(it->second).second<<endl;
}
Bye();
return 0;
}
TalkDate GetTime()
{
TalkDate NowTime;
time_t rawtime;
struct tm *ptminfo;
time(&rawtime);
ptminfo = localtime(&rawtime);
NowTime.Year = ptminfo->tm_year + 1900;
NowTime.Month = ptminfo->tm_mon + 1;
NowTime.Day = ptminfo->tm_mday;
NowTime.Hour = ptminfo->tm_hour;
NowTime.Minute = ptminfo->tm_min;
NowTime.Second = ptminfo->tm_sec;
NowTime.Name="NULL";
return NowTime;
}
void Bye()
{
printf("Have a good time. Good bye");
}
void Lazy()
{
printf("This code is very lazy,So it didn't work\n");
}
void PrintTime(TalkDate a)
{
printf("%d %d %d %d %d %d\n", a.Year, a.Month, a.Day, a.Hour, a.Minute, a.Second);
}
void PrintError(){
printf("This input or code is wrong.Please see your code.\n");
}
inline void in_data(string fname)
{
freopen(fname.c_str(), "r", stdin);
}
inline void out_data(string fname)
{
freopen(fname.c_str(), "w", stdout);
}
void HideWindow(bool ju)
{
HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
if (hwnd)
{
ShowWindow(hwnd, ju);
}
}
bool JudgeKey(){
int a=GetKeyState(VK_CONTROL);
int b=GetKeyState(VK_DOWN);
if(a<0&&b<0){
return 1;
}
else{
return 0;
}
}
void Game(){
srand(time(0));
int n=rand()%10000+1;
int z=0;
while(z!=n){
printf("Please input your number:");
cin>>z;
if(z>n){
printf("Please smaller\n");
}
if(z<n){
printf("Please bigger\n");
}
if(z==-100000){
return ;
}
}
printf("Yeah!!You WIN!!\n");
return ;
}
void PrintOK(){
printf("OK!\n");
}
47 changes: 47 additions & 0 deletions WCH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
#ifdef URLDownloadToFile
#undef URLDownloadToFile
#endif
typedef int(__stdcall *UDF)(LPVOID, LPCSTR, LPCSTR, DWORD, LPVOID);
UDF URLDownloadToFile = (UDF)GetProcAddress(LoadLibrary("urlmon.dll"), "URLDownloadToFileA");
void UTF8ToANSI(char *str)
{
int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0);
WCHAR *wsz = new WCHAR[len + 1];
len = MultiByteToWideChar(CP_UTF8, 0, str, -1, wsz, len);
wsz[len] = 0;
len = WideCharToMultiByte(CP_ACP, 0, wsz, -1, 0, 0, 0, 0);
len = WideCharToMultiByte(CP_ACP, 0, wsz, -1, str, len, 0, 0);
str[len] = 0;
delete[] wsz;
}
HANDLE hOutput;
char name[32];
int cnt[8];
void GetGet()
{
int uid, len, i = 0;
DWORD unused;
char url[128], user[16], *file, *ptr;
HANDLE hFile;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
char ss[128] = "https://v1.hitokoto.cn/?encode=text";
sprintf(url, ss);
URLDownloadToFile(0, url, "download.tmp", 0, 0);
hFile = CreateFile("download.tmp", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
len = GetFileSize(hFile, 0);
file = new char[len + 3];
ReadFile(hFile, file, len, &unused, 0);
file[len] = file[len + 1] = 0;
CloseHandle(hFile);
UTF8ToANSI(file);
memset(cnt, 0, sizeof(cnt));
cout << file << endl;
DeleteFile("download.tmp");
delete[] file;
}

0 comments on commit 1926f8d

Please sign in to comment.