poj-2196
来源:互联网 发布:最大的网络直播平台 编辑:程序博客网 时间:2024/04/30 07:20
//732K938MSG++//228K188MSC++#include <cstdio>#include <cstring>#include <iostream>using namespace std;struct Node {int array1AppearTime;int array2AppearTime;};typedef struct Node Node;Node charAppearTime[26];char str1[1000];char str2[1000];int ABS(int a) {return a > 0? a: -a;}int getMinDistance(char * str1, char * str2) {memset(charAppearTime, 0, sizeof(charAppearTime));// printf("STR: %s %s\n", str1, str2);int L = strlen(str1);for (int i = 0; i < strlen(str1); i++) {// printf("%c %c\n", str1[i], str2[i]);(charAppearTime[str1[i]-'a'].array1AppearTime) += 1;// printf("%d\n", charAppearTime[str1[i]].array1AppearTime);// (charAppearTime[str2[i]].array2AppearTime) += 1;}for (int i = 0; i < strlen(str2); i++) {(charAppearTime[str2[i]-'a'].array2AppearTime) += 1;// printf("%d\n", charAppearTime[str2[i]].array2AppearTime);}int D = 0;for (int i = 0; i <= 25; i++) {// printf("%d %d\n", charAppearTime[i].array1AppearTime, charAppearTime[i].array2AppearTime);D += ABS(charAppearTime[i].array1AppearTime - charAppearTime[i].array2AppearTime);}return D;}int caseNum;int main() {scanf("%d", &caseNum);cin.get();for (int i = 1; i <= caseNum; i++) {cin.getline(str1, 1000);cin.getline(str2, 1000);int d = getMinDistance(str1, str2);printf("Case #%d: %d\n", i, d);}}
水题,朴素法charmap对比字母出现次数, G++和C++的效率差的真多...
0 0
- POJ 2196
- poj-2196
- poj-2196
- POJ 2196
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- CSS布局+static relative fixed absolute
- cocospod 安装和使用
- 快速提高 Vi/Vim 使用效率的原则与途径
- Socket 功能在 Service 中实现【这才是实际的使用情况】
- iOS 系统标题翻译
- poj-2196
- Hibernate的介绍
- HDU 2458 Kindergarten
- 八步详解Hibernate的搭建及使用
- versions 出现Working copy **locked
- Hibernate总结(一)
- HDU 4822 Tri-war
- Hibernate总结(二)
- 网络管理中的常用命令