SRM 441 DIVII 250概述及源码(C语言版)
来源:互联网 发布:android放弃java 编辑:程序博客网 时间:2024/04/30 11:34
Problem Statement
If X and Y are two strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different. For example, the difference between the words "ant" and "art" is 1. You are given two strings, A and B, where the length of A is less than or equal to the length of B. You can apply an arbitrary number of operations to A, where each operation is one of the following:
Choose a character c and add it to the beginning of A.
Choose a character c and add it to the end of A.
Apply the operations in such a way that A and B have the same length and the difference between them is as small as possible. Return this minimum possible difference.
Definition
Class:
DifferentStrings
Method:
minimize
Parameters:
string, string
Returns:
int
Method signature:
int minimize(string A, string B)
(be sure your method is public)
Constraints
-
A and B will each contain between 1 and 50 characters, inclusive.
-
A and B will both contain only lowercase letters ('a'-'z').
-
The length of A will be less than or equal to the length of B.
Examples
0)
"koder"
"topcoder"
Returns: 1
You can prepend "top" to "koder" and you'll get "topkoder". The difference between "topkoder" and "topcoder" is 1.
1)
"hello"
"xello"
Returns: 1
A and B already have the same length so you cannot add any characters to A.
2)
"abc"
"topabcoder"
Returns: 0
3)
"adaabc"
"aababbc"
Returns: 2
4)
"giorgi"
"igroig"
Returns: 6
我的程序:
C语言实现
If X and Y are two strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different. For example, the difference between the words "ant" and "art" is 1. You are given two strings, A and B, where the length of A is less than or equal to the length of B. You can apply an arbitrary number of operations to A, where each operation is one of the following:
Choose a character c and add it to the beginning of A.
Choose a character c and add it to the end of A.
Apply the operations in such a way that A and B have the same length and the difference between them is as small as possible. Return this minimum possible difference.
Definition
Class:
DifferentStrings
Method:
minimize
Parameters:
string, string
Returns:
int
Method signature:
int minimize(string A, string B)
(be sure your method is public)
Constraints
-
A and B will each contain between 1 and 50 characters, inclusive.
-
A and B will both contain only lowercase letters ('a'-'z').
-
The length of A will be less than or equal to the length of B.
Examples
0)
"koder"
"topcoder"
Returns: 1
You can prepend "top" to "koder" and you'll get "topkoder". The difference between "topkoder" and "topcoder" is 1.
1)
"hello"
"xello"
Returns: 1
A and B already have the same length so you cannot add any characters to A.
2)
"abc"
"topabcoder"
Returns: 0
3)
"adaabc"
"aababbc"
Returns: 2
4)
"giorgi"
"igroig"
Returns: 6
我的程序:
#include <stdio.h>#include <math.h>#include <string.h>int main(){ int i,j,min=15,tmp=0; char str1[15],str2[15]; printf("Please input the str1\n"); gets(str1); printf("Please input the str2\n"); gets(str2); for(j=0;str2[j];j++) { if(strlen(str1)<=strlen(str2)-j) { tmp=0; for(i=0;str1[i]&str2[i+j];i++) { if((str1[i]-str2[j+i])) { tmp+=1; } } } if(min>tmp) min=tmp; } printf("there are %d diff\n",min);}
C语言实现
- SRM 441 DIVII 250概述及源码(C语言版)
- SRM 441 DIVII 250概述及源码(C#)
- SRM 440 DIVII 250中文翻译及源码(C#)
- SRM 440 DIVII 500中文翻译及思路(C#)
- SRM 497(DIVII) 250 Filtering
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- SRM 497(DIVII) 500 PermutationSignature
- opentelnet.exe源码(C语言版)
- brainfuck解释器源码(c语言版)
- 约瑟夫问题解决及实现代码(C语言版)
- 排序算法总结及实现(C语言版)
- 俄罗斯方块(C语言版)
- 数据结构(C语言版)
- 数据结构(C语言版)
- Makefile(c语言版)
- 俄罗斯方块(C语言版)
- 万年历(C语言版)
- 队列(C语言版)
- curl使用简单介绍
- php位运算
- Android基础类之BaseAdapter
- C++ Primer(第四版)笔记
- 去除 listview Gridview 滑动到边界 的 阴影
- SRM 441 DIVII 250概述及源码(C语言版)
- 教你制作手机电子书android应用 无技术要求
- PHPCMS 2008 SP3 常用函数
- dev C++ 不能调试的解决方法
- C#实现微信聊天对话框
- 如何利用Microsoft Web Browser控件在VC中创建一个属于自己的浏览器
- 测试视频网站
- 使用Database Link遇到ORA-01017,ORA-02063
- 堆和栈的区别