Help on SPOJ IITKWPCA
时间:2013-09-21
来源:互联网
http://www.spoj.com/problems/IITKWPCA/
Can any one help?
作者: fitcat07 发布时间: 2013-09-21
The following problem seems very easy but I got WA (wrong answer):
http://www.spoj.com/problems/IITKWPCA/
Can any one help?
作者: a8d7e8 发布时间: 2013-09-21
1. Why need to reverse? Would reverse affect the result? I couldn't think of a case yet.2. Case sensitive perhaps.
2. I tried either way.

作者: fitcat07 发布时间: 2013-09-21
1. I agreed. I don't think reverse is needed.
2. I tried either way.

how about the 0 case? " "
作者: a8d7e8 发布时间: 2013-09-21
Btw, how do you compute the distinct set? By sorting?
how about the 0 case? " "
No reverse was done.
In Python, I also used set and reverse each word before putting it into the set.
作者: fitcat07 发布时间: 2013-09-21
Um it might tell a difference.

What is easy in Python and Java but not quite as same in C++? String manipulation?
But you've tried Python too......
In C++, I used std::set. I computed the hash value of each word and put it into the set. Instead of hash values, I also tried std::string (slower method) as the element type of the set.
No reverse wa ...
作者: a8d7e8 发布时间: 2013-09-21
from sets import Set
input = stdin.readlines()
for line in input[1:]:
words = line.strip().split()
s = Set()
for word in words:
s.add(word[::-1])
print len(s)
作者: fitcat07 发布时间: 2013-09-21
作者: a8d7e8 发布时间: 2013-09-21
Range checking?size of string >= 1 &&
作者: fitcat07 发布时间: 2013-09-21
作者: a8d7e8 发布时间: 2013-09-21

I modified the Python version a little bit so that it reads T lines instead of all the lines (there are some extra lines in the input file).
Findings:
1. Case sensitive
2. No need to reverse the words
However, I still don't know why my C++ version got WA.
作者: fitcat07 发布时间: 2013-09-21
#include
#include
#include
using namespace std;
const int MAX_LEN = 10000;
int t;
char line[MAX_LEN+4];
int main() {
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &t);
while (t--) {
fgets(line, sizeof(line), stdin);
set s;
char *p = strtok(line, " \n");
while (p) {
s.insert(string(p));
p = strtok(NULL, " \n");
}
printf("%llu\n", s.size());
}
}
作者: fitcat07 发布时间: 2013-09-21
Most recently accepted answers are PYTH........and one JAVA.
Um it might tell a difference.

What is easy in Python and Java but not quite as same in C++? String manipulation?
But you've tr ...
作者: code4food 发布时间: 2013-09-21
I used "%llu" as mine is a 64-bit system.

作者: fitcat07 发布时间: 2013-09-21
My Python version (WA):
from sets import Set
input = stdin.readlines()
for line in input[1:]:
words = line.strip().split()
s = Set()
for word in words:
s.add(word[::-1])
print len(s)
input = stdin.readlines()
for line in input[1:]:
print len(set(line.split()))
作者: code4food 发布时间: 2013-09-21
作者: fitcat07 发布时间: 2013-09-21
Someone from SPOJ's forum find out the problem. I should use "%u" instead of "%llu" as the judge is a 32-bit system.
I used "%llu" as mine is a 64-bit system.

作者: a8d7e8 发布时间: 2013-09-21
import 'dart:async';
import 'dart:convert';
void total_each_line(var Lines) {
var lines = Lines.trim().split(new RegExp(r"\n"));
for(var line in lines.skip(1)){
var t = line.trim().split(new RegExp(r"\s+"));
//print(t);
var len = t[0].length == 0 ? 0 : new Set.from(t).length;
print(len);
}
}
void main() {
Stream inputStream = stdin.transform(new Utf8Decoder());
StreamSubscription sub = inputStream.listen(
(line) => total_each_line(line),
onDone: () => print(' finished'),
onError: (e) => print(' error'));
}
作者: form5 发布时间: 2013-09-21
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28