Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his book…
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到word里面,直到遇到非字母字符,在word最后放'\0'. 我采用第二种思路,就是用gets()函数逐行读到str字符数组里面,然后逐个把单词提取出来. Count存放的是Dictionary里单词的个数,每提取一个单词,看看Dictionary里有没有该单词,没有的话放到字典里面,并且计数器加1. 由…
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his book…
原题链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756 这道题用STL解答还是比较简单的,下面就给大家分享用 set 和 map 的 AC . 解法一(map): #include <iostream> #include <string> #include <map> using names…
题目链接 题意:输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单词不区分大小写. 刘汝佳算法竞赛入门经典(第二版)P112 #include <iostream> #include <string> #include <set> #include <sstream> using namespace std; set<string> dict;//string集合 int main() { string s,buf; w…
题目链接:https://vjudge.net/contest/211547#problem/C 题目大意: 输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写. Sample Input Adventures in Disneyland Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left.&qu…
题目链接:https://vjudge.net/problem/UVA-10815 题意 找出一段文本中的所有单词,以小写形式按照字典序输出. 思路 用空白符替换文本中所有非字母字符后再次读入. 代码 #include <bits/stdc++.h> using namespace std; set<string> st; int main() { string s; while (cin >> s) { for (char &c : s) { if (isal…
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. F…
/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单dp 题目大意: 给一个字符串, 要求把它分割成若干个子串,使得每个子串都是回文串.问最少可以分割成多少个. 定义:dp[i]表示前0~i内的字符串划分成的最小回文串个数: dp[i] = min(dp[j]+1 | j+1~i是回文串); 先预处理flag[i][j]表示以i~j内的字符串为回文串…
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. Fr…
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. Fr…
Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all…
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英语.于是他每天都读一篇只包含生词的英语文章,并以自己高达450的智商在一秒钟之内记忆下来. 现在给你一篇XY学长今天要读的文章,请你写一个程序,输出他都学习到了哪些单词.要求:如果文章中有相同的单词,那么仅仅输出一次:而且如果两个单词只有大小写不同,将他们视为相同的单词. Input 测试数据将输入…
  Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his bo…
题意:给出一段英文,里面包含一些单词,空格和标点,单词不区分大小写,默认都为小写.按照字典序输出这些单词(这些单词不能有重复,字母全部变成小写) stringstream:包含在头文件#include<sstream>中,能将一个字符串分割,用>>输出某些元素 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include…
参考:https://www.cnblogs.com/yjlblog/p/6947747.html https://blog.csdn.net/hnust_taoshiqian/article/details/43448793 https://blog.csdn.net/liuke19950717/article/details/49450817 https://blog.csdn.net/fanyun_01/article/details/66967710 #include <iostream…
输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单 词不区分大小写. 样例输入: Adventures in Disneyland Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left." So they went home. 样例输出(为了节约篇幅只保留前5行): a adventures blond…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用stringstream来处理中间的标点. ->直接把他变成一个空格. 然后重新输入进去. set默认的字典序就是升序的了. [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #include <bits/stdc++.h> using namespace std; set<string> myset; string s; int main() { //freopen("F:\…
1.set 集合 哦....对了,set有自动按照字典序排序功能..... 声明和插入操作 #include <cstdio> #include <vector> #include <set> using namespace std; int main(){ vector<int> v; ; i < ; i++) { v.push_back(i); v.push_back(i); } set<int> s; s.insert(v.begin…
#include<bits/stdc++.h>using namespace std;set<string> dict;int main(){ string s, buf; while(cin >> s) { for(int i = 0;i < s.length();i++) { if(isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' '; } stringstream ss(s); while(ss >&…
题目链接:https://uva.onlinejudge.org/external/115/11584.pdf 题意: 一个字符串,将它划分一下,使得每个串都是回文串,求最少的回文串个数. 分析: d(i)到第 i 个字符时的最优解(即最少划分为几个回文串),就有方程  d(i) = min(d(j)) + 1;(其中s[j+1,i]要是回文串). 这样一来,枚举就是O(n^2)的复杂度,如果按照普通的判断s[j+1,i]是否是回文串,时间复杂度为O(n^3);先用O(n^2)的复杂度预处理is…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756 题意:很简单,把输入的文本,排序按字典序输出,相当于制作字典. 主要是set和stringstream的运用. 对于stringstream有个简单的程序. #include<iostream> #include<sstream> using namespac…
UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=599&problem=757&mosmsg=Submission+received+with+ID+14332151" target="_blank" style="">题目链接 题意:一个迷宫,每一个点限制了从哪一方向来的.仅仅能往左右前…
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪(没有计算机有该项服务). 思路:(见大白70页,我的方程与大白不同) 把n个集合P1.P2.Pn分成尽量多的组,使得每组中全部集合的并集等于全集,这里的集合Pi是计算机i及其相邻计算机的集合,用cover[i]表示若干Pi的集合S中全部集合的并集,dp[s]表示子集s最多能够分成多少组,则 假设co…
 Message Decoding  Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the characters of the message. The second part contains a pattern that represents the message. You must…
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: #include <stdio.h> #include <string.h> long long a, p; long long pow_mod(long long x, long long k, long long mod) { long long ans = 1; while (k…
UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) 分, 而且每一份的长度都为 L / gcd(l,k).因此平方对于奇数长度不变,偶数则会分裂成两份长度同样的循环,因此假设B中偶数长度的循环个数不为偶数必定不存在A了 代码: #include <stdio.h> #include <string.h> const int N = 30…
UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,例如以下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cel…
题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap−12≡1%p #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll pow_mod (ll a, ll n, ll mod) { ll ans = 1; while…
题目例如以下: The Sultan's Successors  The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoever performs best at some test. Itis possible for an…