#include <cstdio>
#include <string.h>
#include <ctime>
#include <cstdlib>
#include <string>
using std::string;
struct Timestamper {
clock_t start;
Timestamper() : start(clock()) {}
~Timestamper() {
printf("Time=%.3fs\n", (clock() - start) * 1.0 / CLOCKS_PER_SEC);
}
};
int len;
template<typename T>
void calc1(T s) {
Timestamper t;
int ans = 0;
for (int i = 0; i < len ; i++)
for (int j = 0; j < len ; j++)
ans += s[i] == s[j];
printf("%d\n", ans);
}
template<typename T>
void calc2(T s) {
Timestamper t;
int ans = 0;
for (size_t i = 0; i < s.length(); i++)
for (size_t j = 0; j < s.length(); j++)
ans += s[i] == s[j];
printf("%d\n", ans);
}
const int MAXL = int(1.5e4);
char s[MAXL + 1];
int main() {
srand(123456);
for (int i = 0; i < MAXL; i++)
s[i] = 'a' + (rand() % 26);
s[MAXL] = 0;
len=MAXL;
calc1<const char*>(s);
calc1< char*>(s);
string str(s);
calc2<const string&>(str);
calc2<const string >(str);
calc2< string >(str);
calc2< string >(std::move(str));
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgc3RkOjpzdHJpbmc7CgpzdHJ1Y3QgVGltZXN0YW1wZXIgewogIGNsb2NrX3Qgc3RhcnQ7CgogIFRpbWVzdGFtcGVyKCkgOiBzdGFydChjbG9jaygpKSB7fQogIH5UaW1lc3RhbXBlcigpIHsKICAgIHByaW50ZigiVGltZT0lLjNmc1xuIiwgKGNsb2NrKCkgLSBzdGFydCkgKiAxLjAgLyBDTE9DS1NfUEVSX1NFQyk7CiAgfQp9OwoKaW50IGxlbjsKCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnZvaWQgY2FsYzEoVCBzKSB7CiAgVGltZXN0YW1wZXIgdDsKICBpbnQgYW5zID0gMDsKICBmb3IgKGludCBpID0gMDsgaSA8IGxlbiA7IGkr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