Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
15 kB
7
Indexable
Never
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

#define CMD_INIT       100
#define CMD_INSERT     200
#define CMD_MOVECURSOR 300
#define CMD_COUNT      400

extern void init(int H, int W, char mStr[]);
extern void insert(char mChar);
extern char moveCursor(int mRow, int mCol);
extern int countCharacter(char mChar);

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

static bool run()
{
	bool correct = false;
	int queryCnt;
	scanf("%d", &queryCnt);
	int H, W;
	char mChar;
	static char mStr[90001];

	while (queryCnt--)
	{
		int cmd;
		scanf("%d", &cmd);

		if (cmd == CMD_INIT)
		{
			scanf("%d %d %s", &H, &W, mStr);
			init(H, W, mStr);
			correct = true;
		}
		else if (cmd == CMD_INSERT)
		{
			scanf(" %c", &mChar);
			insert(mChar);
		}
		else if (cmd == CMD_MOVECURSOR)
		{
			int mRow, mCol;
			scanf("%d %d", &mRow, &mCol);

			char ret = moveCursor(mRow, mCol);

			char ans;
			scanf(" %c", &ans);
			if (ret != ans)
			{
				correct = false;
			}
		}
		else if (cmd == CMD_COUNT)
		{
			scanf(" %c", &mChar);

			int ret = countCharacter(mChar);

			int ans;
			scanf("%d", &ans);
			if (ret != ans)
			{
				correct = false;
			}
		}
	}
	return correct;
}

int main()
{
	setbuf(stdout, NULL);
	freopen("sample_input.txt", "r", stdin);

	int T, MARK;
	scanf("%d %d", &T, &MARK);

	for (int tc = 1; tc <= T; tc++)
	{
		int score = run() ? MARK : 0;
		printf("#%d %d\n", tc, score);
	}
	return 0;
}

***

#include<iostream>
using namespace std;

struct Node {
	char data;
	Node *pre;
	Node *next;
};

Node* createNode(char val) {
	Node* temp = new Node();
	temp->data = val;
	temp->pre = NULL;
	temp->next = NULL;
	return temp;
}
void connectNode(Node* front, Node* end) {
	front->next = end;
	end->pre = front;
}
void insertNode(Node* front, Node* p, Node* end) {
	connectNode(front, p);
	connectNode(p, end);
}
void removeNode(Node* p) {
	connectNode(p->pre, p->next);
}

struct List {
	Node *head;
	Node *tail;
	int size;
	int cnt[29];
}NotepadLine[301];

struct Cursor {
	int row;
	int col;
}mouse;

int mH, mW, mLine;

void init(int H, int W, char mStr[]) {
	mH = H; 
	mW = W;
	mouse.col = mouse.row = 1;

	for (int i = 1; i <= mH; i++) {
		NotepadLine[i].size = 0;
		NotepadLine[i].head = new Node();
		NotepadLine[i].tail = new Node();
		connectNode(NotepadLine[i].head, NotepadLine[i].tail);
	
		for (int j = 0; j < 29; j++) {
			NotepadLine[i].cnt[j] = 0;
		}
	}
	mLine = 1;

	for (int i = 0; mStr[i] != '\0'; i++) {
		Node* temp = createNode(mStr[i]);
		insertNode(NotepadLine[mLine].tail->pre, temp, NotepadLine[mLine].tail);
		NotepadLine[mLine].cnt[mStr[i] - 'a']++;
		NotepadLine[mLine].size++;
		if (NotepadLine[mLine].size >= mW) {
			mLine++;
		}
	}
}

void insert(char mChar) {
	Node* temp = createNode(mChar);
	int hang = mouse.row;
	int cot = mouse.col;
	Node* cur = NotepadLine[hang].head->next;

	for (int i = 1; i < cot; i++) {
		cur = cur->next;
	}
	insertNode(cur->pre, temp, cur);
	mouse.col++;
	NotepadLine[hang].size++;
	NotepadLine[hang].cnt[mChar - 'a']++;

	while (NotepadLine[hang].size > mW) {
		Node* temp1 = NotepadLine[hang].tail->pre;
		connectNode(temp1->pre, temp1->next);
		NotepadLine[hang].size--;
		NotepadLine[hang].cnt[temp1->data - 'a']--;
		hang++;
		Node* cur1 = NotepadLine[hang].head;
		insertNode(cur1, temp1, cur1->next);
		NotepadLine[hang].size++;
		NotepadLine[hang].cnt[temp1->data - 'a']++;
	}

	if (hang > mLine) {
		mLine = hang;
	}

	if (mouse.col > mW) {
		mouse.row++;
		mouse.col = 1;
	}
}

char moveCursor(int mRow, int mCol) {
	if (mRow > mLine || (mRow == mLine && mCol > NotepadLine[mLine].size)) {
		mouse.row = mLine;
		mouse.col = NotepadLine[mLine].size + 1;
		return '$';
	}
	mouse.col = mCol;
	mouse.row = mRow;
	Node* cur = NotepadLine[mRow].head->next;

	for (int i = 1; i < mCol; i++) {
		cur = cur->next;
	}
	return cur->data;
}

int countCharacter(char mChar) {
	int res = 0;
	for (int i = mouse.row; i <= mLine; i++) {
		res += NotepadLine[i].cnt[mChar - 'a'];
	}
	Node* temp = NotepadLine[mouse.row].head->next;

	for (int i = 1; i < mouse.col; i++) {
		if (temp->data == mChar) {
			res--;
		}
		temp = temp->next;
	}
	return res;
}

***
25 100
19
100 3 4 bcdeg
400 b 1
300 2 1 g
200 f
300 1 4 e
400 f 1
300 2 4 $
200 e
200 b
400 b 0
300 3 1 $
300 1 1 b
200 a
200 b
200 a
400 b 2
300 1 1 a
400 b 3
400 a 2
141
100 5 5 dkrbddmbdgbk
400 d 4
400 d 4
300 1 2 k
400 i 0
400 k 2
400 y 0
400 i 0
400 b 3
400 z 0
400 k 2
400 i 0
400 b 3
400 j 0
400 z 0
400 i 0
400 g 1
200 k
400 k 2
400 j 0
200 i
400 s 0
400 y 0
400 k 2
400 d 3
400 y 0
400 d 3
400 s 0
200 z
400 d 3
400 j 0
400 k 2
400 z 0
400 s 0
400 b 3
300 1 4 z
400 b 3
300 1 3 i
400 b 3
400 j 0
200 y
400 s 0
400 m 1
400 y 0
400 m 1
400 z 1
400 g 1
400 g 1
400 s 0
400 m 1
400 j 0
400 k 2
400 g 1
400 k 2
400 j 0
400 g 1
400 b 3
400 g 1
400 i 1
400 m 1
400 s 0
400 m 1
400 b 3
400 g 1
400 m 1
400 b 3
400 m 1
400 i 1
400 z 1
400 j 0
400 s 0
400 z 1
200 i
300 1 3 y
400 i 2
400 g 1
400 y 1
400 m 1
400 i 2
400 j 0
300 2 5 d
400 b 2
400 k 1
200 m
400 y 0
400 g 1
400 m 1
400 g 1
400 i 0
400 b 2
400 z 0
400 j 0
200 i
400 y 0
400 i 0
400 y 0
400 z 0
400 b 2
400 m 1
300 3 5 b
400 g 1
400 g 1
400 k 1
200 k
400 m 0
400 i 0
400 m 0
400 s 0
400 s 0
400 d 1
400 y 0
400 s 0
400 j 0
300 3 1 i
400 b 2
400 s 0
400 d 3
400 y 0
400 s 0
400 d 3
400 x 0
400 z 0
400 m 1
300 2 4 b
400 y 0
400 y 0
300 4 2 d
400 d 1
400 k 1
400 m 0
300 3 3 d
400 z 0
400 m 1
400 j 0
400 i 0
400 i 0
400 z 0
200 m
200 y
400 m 1
400 g 1
321
100 20 30 mvlycyhddcolkxrbjrqvrvlgqgnjkjsbxjdthltmmekhwlvzgmxhfqjiflushzunyaouklpqzjduaarfpntmrlcotmzwoafdxajhaksuureleocqlglaskmcjmjleaykfhwjrwictwbylkruwbhrmwxwpafhzuimfgnqywdjarzxkfahqtpmbzufxltylwxuvsfqtevriiqosnjziwckxqtsmqtpdadqbcukcorztlylriskpvuroxtlloxupvudksaphibauyntxkfunxzpfftrayfauyatfletuqorfbfq
400 w 11
400 g 5
200 m
300 5 11 h
300 3 26 r
200 t
200 d
300 3 22 p
400 r 12
300 5 14 w
400 r 10
300 4 19 r
400 c 6
400 h 5
300 2 15 h
400 b 6
200 f
300 10 12 f
200 a
300 7 19 f
200 e
300 3 12 l
200 a
400 i 7
300 11 25 $
400 g 0
400 r 0
200 o
200 i
200 a
400 n 0
400 c 0
200 j
400 b 0
300 4 21 r
200 w
400 e 6
300 9 5 i
300 10 13 p
400 a 5
200 o
200 x
400 v 0
400 y 2
400 z 0
400 e 1
400 m 0
400 n 0
400 z 0
300 6 29 k
400 l 7
200 a
300 2 14 k
200 h
200 i
400 j 9
400 z 10
200 e
300 5 14 e
300 10 3 i
400 l 1
300 1 15 x
400 c 7
400 c 7
300 10 9 t
200 x
200 z
200 q
300 1 13 l
300 10 16 u
300 10 25 f
200 f
400 i 1
200 k
400 v 0
300 4 10 w
400 f 15
400 o 9
300 9 15 r
200 j
200 s
300 4 10 w
200 o
200 t
200 e
400 h 6
200 j
300 9 30 p
300 6 17 a
200 p
200 h
400 c 3
300 6 14 x
400 k 7
300 6 22 z
200 q
300 1 13 l
300 1 23 v
200 d
300 4 3 d
300 1 8 h
200 u
400 x 15
400 y 9
200 d
200 b
400 d 11
400 i 10
300 4 16 e
400 w 11
400 p 8
400 q 12
200 s
400 p 8
400 o 9
200 o
400 y 8
200 x
400 r 11
300 4 20 j
400 v 4
200 o
300 2 5 j
300 7 1 z
200 y
400 a 11
300 6 3 j
300 14 28 $
300 5 1 a
300 6 10 b
300 8 15 e
300 8 23 n
200 r
200 y
200 e
200 t
400 w 1
200 d
400 y 4
400 f 8
400 r 5
200 f
400 t 8
300 5 11 o
400 v 4
400 h 6
300 1 19 r
300 1 14 c
300 4 23 o
400 d 6
200 r
300 1 12 d
200 e
300 1 2 m
300 1 8 u
400 u 19
400 l 19
400 d 13
200 h
200 j
400 s 11
400 l 19
200 x
200 k
300 6 24 h
200 o
200 g
200 g
300 1 25 b
300 1 24 r
400 r 18
400 p 10
400 a 21
400 p 10
200 n
200 u
400 v 7
400 d 10
200 m
400 m 11
200 e
200 f
200 s
400 e 10
200 h
300 4 22 o
400 u 14
400 f 16
300 6 12 k
400 j 5
200 n
400 q 11
400 o 8
200 a
200 s
300 4 30 x
400 g 4
200 a
300 8 27 x
300 3 28 o
400 o 15
400 o 15
400 j 10
400 t 17
300 13 9 $
200 f
400 h 0
400 y 0
200 a
300 9 5 e
300 7 17 a
300 7 6 g
400 u 11
400 j 4
400 l 7
200 x
200 v
400 q 11
300 3 27 a
400 a 24
300 11 19 i
300 8 29 x
300 3 18 f
400 c 7
300 1 22 k
300 6 14 a
200 o
300 7 21 f
400 e 4
200 r
300 6 4 m
200 j
300 1 9 j
400 h 14
200 b
400 d 13
300 5 9 a
300 8 27 x
400 y 6
300 7 22 a
200 o
200 x
200 c
400 c 3
200 p
400 s 6
400 b 4
200 s
300 1 17 e
200 k
200 a
400 n 9
400 p 11
400 a 24
400 x 18
200 a
300 3 25 s
300 8 16 d
300 2 8 r
200 b
400 r 18
200 m
300 8 11 m
300 8 5 h
400 w 3
300 10 7 z
300 7 20 m
200 g
200 e
300 4 17 r
400 s 11
200 d
300 4 16 a
300 11 23 l
200 e
300 7 5 w
300 8 16 g
300 3 8 e
300 9 11 l
300 4 16 a
300 10 19 m
300 4 29 o
400 l 12
300 7 29 h
300 10 25 d
400 t 6
400 n 2
400 p 4
400 f 9
400 t 6
200 f
200 e
300 7 8 l
300 13 20 o
200 e
300 5 27 w
400 n 5
200 a
400 h 6
200 w
400 b 6
300 8 9 f
200 f
400 a 12
200 h
400 s 6
200 f
200 o
400 y 8
400 w 3
400 d 5
300 6 12 k
300 10 14 n
200 e
400 f 10
200 q
400 f 10
400 b 3
400 i 4
400 u 8
521
100 30 20 wwpwppppwsppspppppsswwsswssswpwpsspdpwwspsswpwwspwwsppsppppspweswssspsppppsspppwsswspsppwpwwwssswwwwwswpwpspwpppwwwwpwwwswwwspsswssswwwpppssppwwpwspwpsspwppsssssppwsppwsspspswpwppowssswwwsswpwssspwwppwswsspspspssswspwsppwpsppwwwwswwpwpwpsspwppppwssssswsswwsppwpwwsswsswpwsswpwpwwwwsppeswwwspspxwswwsp
300 13 7 s
200 w
200 s
300 28 6 $
400 w 0
300 5 18 w
300 15 6 p
400 w 6
300 4 2 w
200 w
200 w
400 s 81
200 s
200 p
400 s 81
300 1 6 p
200 p
300 6 18 w
200 s
300 5 15 p
200 s
200 s
200 w
200 s
300 12 4 w
200 p
300 13 18 w
200 p
200 w
400 s 21
400 w 22
300 8 8 p
300 8 6 p
300 7 12 w
200 s
200 p
300 15 18 w
300 11 14 s
300 6 11 s
400 w 72
400 s 69
300 4 14 p
400 p 75
300 10 10 p
300 8 10 p
200 p
300 2 4 s
300 8 2 s
300 8 6 w
200 p
300 14 7 s
200 s
200 w
400 s 19
400 w 21
300 12 4 p
400 p 28
300 15 20 w
400 p 5
200 w
300 6 16 s
300 1 12 p
200 s
200 s
300 5 15 p
200 p
300 11 9 w
300 23 11 $
200 p
400 w 0
200 p
400 p 0
300 1 16 s
300 6 20 p
400 w 72
400 s 68
200 w
200 w
400 w 72
300 5 16 p
300 2 19 d
300 10 4 s
400 w 51
200 w
200 s
300 9 10 s
400 p 48
400 p 48
200 s
200 s
200 w
300 13 11 w
400 s 25
400 s 25
200 p
300 2 18 p
200 p
200 w
300 6 7 w
400 s 76
200 w
400 w 84
400 p 68
400 w 84
300 15 15 w
300 14 20 s
300 6 15 w
300 9 6 w
200 w
200 w
400 p 52
300 8 14 p
200 w
200 s
200 w
400 s 62
200 s
200 p
400 w 63
400 w 63
200 w
200 s
400 s 62
200 p
400 w 63
200 p
300 2 15 p
200 s
200 s
300 9 6 w
300 4 4 p
200 s
400 w 100
300 13 9 p
200 p
300 9 19 w
200 p
200 s
400 s 60
200 s
400 s 60
300 6 17 w
300 14 15 w
400 w 33
300 20 18 $
200 p
300 1 17 p
300 5 5 p
400 w 96
300 7 5 s
200 p
300 3 4 p
300 10 14 s
300 14 14 w
200 p
300 11 13 w
300 13 19 s
200 s
300 2 12 w
300 5 4 p
300 7 18 w
200 s
300 13 12 p
200 s
200 w
200 w
200 s
300 15 5 s
300 4 11 w
300 12 17 p
400 w 45
200 p
200 p
200 w
300 2 19 s
200 s
300 15 9 s
300 10 12 p
200 s
200 s
400 s 62
300 2 3 s
200 w
300 7 2 s
400 p 78
200 p
300 2 11 s
200 p
300 3 6 d
200 p
200 s
300 5 3 s
400 p 92
300 13 4 w
300 6 19 s
300 10 5 w
300 7 8 p
300 10 19 p
300 1 18 p
300 8 3 w
300 11 6 w
200 w
200 w
200 w
400 p 53
200 s
300 9 8 s
200 p
200 w
300 8 12 p
300 2 4 s
300 11 3 s
400 s 62
200 p
400 s 62
400 w 61
200 s
300 4 6 p
400 s 107
400 s 107
200 s
300 11 7 w
400 w 61
400 w 61
300 15 10 w
400 s 27
300 5 20 s
400 p 86
300 11 10 p
200 w
300 11 18 p
300 5 10 p
300 15 15 w
400 w 36
200 w
300 9 5 w
200 p
200 w
200 p
200 w
200 s
200 w
300 6 10 s
200 w
300 8 7 w
200 p
400 p 75
400 s 83
300 11 4 w
200 p
200 w
300 12 1 p
400 s 59
200 w
300 9 6 s
200 w
200 p
200 p
300 15 12 s
300 3 9 p
200 w
300 15 13 s
300 10 20 w
200 p
400 w 71
300 9 18 w
200 s
200 w
300 11 12 w
200 s
200 p
200 p
200 w
300 1 3 p
300 8 3 s
400 p 82
200 s
200 w
200 p
200 p
200 w
200 s
200 s
300 5 7 s
400 s 106
300 9 6 w
200 w
400 s 83
300 4 14 p
400 s 111
400 p 108
400 s 111
400 w 121
300 10 7 w
400 s 75
400 s 75
300 12 18 s
200 w
300 11 14 s
200 s
200 p
400 p 61
300 15 13 s
300 6 3 s
400 p 98
200 p
300 6 13 s
300 2 5 w
300 2 5 w
200 s
300 14 6 p
200 p
300 14 11 p
300 8 12 s
300 3 15 p
400 w 127
400 p 119
400 p 119
300 15 14 p
300 10 7 w
200 w
200 p
300 8 10 s
400 w 98
300 4 13 p
300 4 9 p
300 14 7 p
300 4 8 s
400 p 116
200 s
300 7 1 w
200 y
300 4 6 s
300 7 13 s
300 14 12 w
400 s 51
200 w
300 4 14 p
400 s 112
200 s
400 p 114
300 12 7 p
200 w
400 w 70
200 s
200 s
200 p
300 7 9 w
300 8 13 s
300 10 10 w
200 s
200 p
300 15 10 p
200 s
300 10 16 w
200 s
300 9 19 s
400 s 85
400 w 88
400 p 83
200 e
200 w
200 p
200 w
300 4 18 s
200 w
300 3 17 s
200 w
200 p
200 w
200 p
300 7 3 s
300 4 8 w
400 s 123
200 w
300 3 18 p
200 w
300 15 2 p
300 4 8 p
200 p
300 3 8 s
200 p
200 p
200 w
200 p
400 w 140
300 14 12 w
300 13 7 s
300 9 17 w
300 6 4 s
400 w 123
400 w 123
400 p 111
300 15 19 s
300 13 13 p
300 13 12 s
400 p 60
200 s
200 p
300 4 14 w
200 w
200 w
400 s 124
400 s 124
300 2 4 s
300 1 18 p
300 2 16 p
200 s
200 p
400 s 134
300 6 2 s
400 e 2
200 s
200 w
400 p 113
300 9 17 s
300 2 10 w
200 p
400 s 139
400 s 139
400 p 138
300 3 7 p
300 13 17 p
400 p 63
200 p
200 w
200 s
300 1 19 p
300 13 3 p
300 7 15 s
300 10 9 w
300 13 9 s
400 w 74
200 w
200 p
400 p 65
200 p
300 4 6 p
400 s 128
200 w
400 p 129
200 w
400 s 128
200 p
200 w
400 w 140
300 9 4 w
400 s 98
200 w
300 12 8 w
300 15 5 p
300 11 2 s
300 7 13 p
400 s 106
400 p 106
300 8 2 p
200 p
300 7 8 w
200 s
200 w
200 s
200 p
200 s
400 s 108
300 5 3 w
400 p 126
300 4 18 s
200 w
400 w 138
200 s
400 p 128
300 8 12 w
300 1 17 p
300 3 8 w
200 p
300 8 20 w
400 s 100
300 11 16 s
300 5 17 s
200 w
300 6 11 s
300 15 11 s
300 9 11 p
300 10 4 p
400 s 97
400 w 105
200 p
200 s
200 w
200 s
400 s 97
300 12 3 p
400 w 89
200 s
300 6 17 s
400 p 119
200 s
400 s 120
300 11 10 w
300 10 15 w
200 w
400 w 104
200 s
300 14 15 s
200 w
300 15 15 w
300 2 16 w
400 s 146
200 s
200 w
200 p
400 s 146
400 s 146
400 p 145
200 w
300 9 17 p
200 s
200 w
200 s
200 p
Leave a Comment