Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions 13307130414/assignment11/GREAT SWERC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <iostream>
#include <cstring>
using namespace std;

bool str[26]; // to mark if a letter has existed
bool num[10]; // to mark if a number is used
string buf[10];
int a[10];
int cnt; // count how many different characters
int ans;

struct Node {
char c;
int n;
bool flag; // to mark if this letter is the leftmost one
Node() : flag(false) {}
} node[10];

bool check() {
for (int i = 0; i < cnt; i++) {
if (node[i].flag == true && a[i] == 0)
return false;
}
int temp = 0;
for (int i = 0; i < cnt; i++)
temp += a[i] * node[i].n;
if (temp == 0) return true;
else return false;
}

void dfs(int i) {
if (i > cnt) return;
for(int j = 0; j < 10; j++) {
if (i == 0) memset(num, false, sizeof(num));
if (num[j] == true) continue;
a[i] = j;
num[j] = true;
if (i == cnt-1 && check()) ans++;
dfs(i+1);
num[j] = false;
}
}

int main() {
int n;
cin >> n;
memset(str, false, sizeof(str));
cnt = 0;
ans = 0;
for (int i = 0; i < n; i++)
cin >> buf[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < buf[i].length(); j++) {
int t;
if (str[buf[i][j]-'A'] == true) {
for (t = 0; node[t].c != buf[i][j]; t++) ;
}
else {
t = cnt;
str[buf[i][j]-'A'] = true;
cnt++;
}
node[t].c = buf[i][j];
int temp = 1;
for (int l = 0; l < buf[i].length()-j-1; l++)
temp *= 10;
if (i != n-1) node[t].n += temp;
else node[t].n -= temp;
if (j == 0) node[t].flag = true;
}
}
dfs(0);
cout << ans << endl;
}
25 changes: 25 additions & 0 deletions 13307130414/assignment11/POJ 3364 Black and white painting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
//freopen("3364.txt", "r", stdin);
int n,m,c;
while (1) {
cin >> n >> m >> c;
if (n == 0 && m == 0 && c == 0) return 0;
if (n < 8 || m < 8) {
cout << "0" << endl;
continue;
}
int ans = 0;
if (c == 1) {
ans = ((m-7)*(n-7)+1)/2;
}
else {
ans = ((m-7)*(n-1-7)+1)/2;
ans += (m-7)/2;
}
cout << ans << endl;
}
}
76 changes: 76 additions & 0 deletions 13307130414/assignment11/POJ 3366 Deli Deli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int H = 100007;
int hashtable[H];

struct Node {
char before[25];
char after[25];
int next;
Node() : next(-1) {}
} node[25];

int ELFhash(char* key) {
unsigned long g,h=0;
while(*key)
{
h=(h<<4)+*key++;
g=h & 0xf0000000L;
if(g) h^=g>>24;
h&=~g;
}
return h%H;
}

void inserthash(char *s, int i) {
int h = ELFhash(s);
node[i].next = hashtable[h];
hashtable[h] = i;
}

int searchhash(char *s) {
int h = ELFhash(s);
int next = hashtable[h];
while (next != -1) {
if (!strcmp(node[next].before, s)) return next;
next = node[next].next;
}
return -1;
}

int main() {
//freopen("3366.txt", "r", stdin);
int l,n;
cin >> l >> n;
memset(hashtable, -1, sizeof(hashtable));
for (int i = 0; i < l; i++) {
cin >> node[i].before >> node[i].after;
inserthash(node[i].before, i);
}
for (int i = 0; i < n; i++) {
char str[25];
cin >> str;
if (searchhash(str) != -1) {
cout << node[searchhash(str)].after << endl;
}
else if (str[strlen(str) - 1] == 'y') {
if (strlen(str) > 1 && str[strlen(str) -2] == 'a' || str[strlen(str) -2] == 'e' ||
str[strlen(str) -2] == 'i' || str[strlen(str) -2] == 'u' || str[strlen(str) -2] == 'o')
cout << str << 's' << endl;
else {
str[strlen(str) - 1] = '\0';
cout << str << "ies" << endl;
}
}
else if (str[strlen(str)-1] == 'o' || str[strlen(str)-1] == 's' || str[strlen(str)-1] == 'x'
|| (str[strlen(str)-1] == 'h' && (str[strlen(str)-2] == 'c' || str[strlen(str)-2] == 's'))) {
cout << str << "es" << endl;
}
else
cout << str << "s" << endl;
}
return 0;
}
65 changes: 65 additions & 0 deletions 13307130414/assignment11/POJ 3367 Expressions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 10010;

vector <int> v;
char str[N];
pair <int, int> p[N];
int len;

void init() {
len = strlen(str);
for (int i = 0; i < len; i++)
p[i].first = p[i].second = -1;
v.clear();
}

void output() {
string ans = "";
queue <int> q;
q.push(len-1);
while(!q.empty()) {
int t = q.front();
q.pop();
ans += str[t];
if (p[t].first != -1) {
q.push(p[t].first);
q.push(p[t].second);
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}

int main() {
//freopen("3367.txt", "r", stdin);
int cas;
cin >> cas;
while(cas--) {
cin >> str;
init();
for (int i = 0; i < len; i++) {
if (islower(str[i])) {
v.push_back(i);
}
else {
int a = v.back();
v.pop_back();
int b = v.back();
v.pop_back();
p[i] = make_pair(b,a);
v.push_back(i);
//cout << str[i] << ' ' << str[b] << ' ' << str[a] << endl;
}
}
output();
}
}
44 changes: 44 additions & 0 deletions 13307130414/assignment11/POJ 3370 Halloween treats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int mod[100010];
int a[100010];

int main() {
int c,n;
while(1) {
scanf("%d%d", &c, &n);
if (c == 0 && n == 0) return 0;
memset(mod, -1, sizeof(mod));
long long sum = 0;
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int i;
for (i = 0; i < n; i++) {
sum += a[i];
if (sum%c == 0) {
for (int j = 1; j <= i+1; j++) {
printf("%d", j);
if (j != i+1)
printf(" ");
}
printf("\n");
break;
}
else if (mod[sum%c] != -1) {
for (int j = mod[sum%c]+1; j <= i+1; j++) {
printf("%d", j);
if (j != i+1)
printf(" ");
}
printf("\n");
break;
}
else
mod[sum%c] = i+1;
}
if (i == n) printf("no sweets\n");
}
}