(SOJ) Is it a word ladder? (词梯)
来源:互联网 发布:java弹球游戏 编辑:程序博客网 时间:2024/05/16 01:43
该题目的大意是:判断一串字符串是否能构成词梯(任意相连的两个字符串之间有且只有一个字母不同)。
#include <iostream>#include <cstdio>#include <cstring>#include <string> #include <vector>#include <list>#include <set>#include <queue>#include <deque>#include <map>#include <algorithm>#include <cstdlib>#include <cmath>#include <ctime>#include <iomanip>#include <fstream>using namespace std ;bool isLadder ( vector <string>& v , int m ){ for ( int i = 0 ; i < m - 1 ; i ++ ) { string s1 = v[i] , s2 = v[i+1] ; int dif = 0 ; if ( s1.size() != s2.size() ) return false ; for ( int k = 0 ; k < s1.size() ; k ++ ) { if ( s1[k] != s2[k] ) dif ++ ; } if ( dif != 1 ) return false ; } return true ;}int main (){ int n , m ; string s ; cin >> n ; while ( n -- ) { cin >> m ; vector <string> v ; v.clear() ; for ( int i = 0 ; i < m ; i ++ ) { cin >> s ; v.push_back( s ) ; } if ( isLadder ( v , m ) ) cout << "Yes" << endl ; else cout << "No" << endl ; } return 0 ;}
0 0
- (SOJ) Is it a word ladder? (词梯)
- (SOJ) check if a word is on a given Boggle board
- Word Ladder
- Word Ladder
- word ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- Word Ladder
- MyBatis 一次执行多条SQL语句
- spring-guide之rest-service
- 257_属性动画xml使用
- java设计模式之命令模式
- 内存优化的解决方案(最全面的总结!如何合理的使用内存)
- (SOJ) Is it a word ladder? (词梯)
- qt基础总结
- 简单理解设计模式之外观模式
- 如何将tomcat注册成windows系统服务方法
- [NOI 2014] 随机数生成器:模拟,贪心
- 258_密码必须由6-20位英文字母或数字组成
- 学习整理——Java集合Collection
- [Lintcode]Evaluate Reverse Polish Notation
- 链表 交并差