HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了。
1020.
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
ABC
ABBCCC
A2B3C
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,count;;
cin>>n;
while(n--)
{
string str;
cin>>str;
for(int i=;i<(int)str.length();i++)
{
count=;
while(str[i]==str[i+])
{
count++;i++;
}
if(count!=)
cout<<count;
cout<<str[i];
}
cout<<endl;
}
return ;
}
1020
1039.
FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:
It must contain at least one vowel.
It cannot contain three consecutive vowels or three consecutive consonants.
It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.
(For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.
#include<iostream>
#include<string>
using namespace std;
bool search1(string str)
{
for(int i=;i<=(int)str.length()-;i++)
{
if(str[i]=='a'||str[i]=='e') return true;
if(str[i]=='i'||str[i]=='o'||str[i]=='u') return true;
}
return false;
}
bool search2(string str)
{
int count1=,count2=;
for(int i=;i<=(int)str.length()-;i++)
{
if(i!=&&str[i-]==str[i])
{if(str[i]=='o'||str[i]=='e');
else return false;}
if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
{
count1++;
count2=;
}
else
{
count2++;
count1=;
}
if(count1>=||count2>=)
return false;
}
return true;
}
int main()
{
string str;
while()
{
cin>>str;
if(str=="end")
break;
if(search1(str)&&search2(str))
cout<<'<'<<str<<'>'<<" is acceptable."<<endl;
else
cout<<'<'<<str<<'>'<<" is not acceptable."<<endl;
} }
1062.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
olleh !dlrow
m'I morf .udh
I ekil .mca
I'm from hdu.
I like acm.
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
#include<iostream>
#include<string>
using namespace std;
const int maxn=;
char a[maxn],b[maxn];
void print(char *str)
{
for(int i=strlen(str)-;i>=;i--)
cout<<str[i];
}
int main()
{
int n,i,j,len;
cin>>n;
getchar();
while(n--)
{
gets(a);
len=strlen(a);
a[len]=' ';
a[len+]='\0';
b[]='\0';
for(i=,j=;i<=len;i++)
{
if(a[i]==' ')
{
print(b);
b[]='\0';
cout<<(i==len?'\n':' ');
j=;
}
else
{
b[j]=a[i];
j++;
b[j]='\0';
}
}
}
return ;
}
1088.
Now, who can forget to install a HTML browser? This is very easy because most of the times you don't need one on a MAC because there is a Acrobate Reader which is native to MAC. But if you ever need one, what do you do?
Your task is to write a small html-browser. It should only display the content of the input-file and knows only the html commands (tags) <br> which is a linebreak and <hr> which is a horizontal ruler. Then you should treat all tabulators, spaces and newlines as one space and display the resulting text with no more than 80 characters on a line.
A word is a sequence of letters, numbers and punctuation. For example, "abc,123" is one word, but "abc, 123" are two words, namely "abc," and "123". A word is always shorter than 81 characters and does not contain any '<' or '>'. All HTML tags are either <br> or <hr>.
. If you read a word in the input and the resulting line does not get longer than 80 chars, print it, else print it on a new line.
. If you read a <br> in the input, start a new line.
. If you read a <hr> in the input, start a new line unless you already are at the beginning of a line, display 80 characters of '-' and start a new line (again).
The last line is ended by a newline character.
ziemlich lange Zeile, die in Html
aber nicht umgebrochen wird.
<br>
Zwei <br> <br> produzieren zwei Newlines.
Es gibt auch noch das tag <hr> was einen Trenner darstellt.
Zwei <hr> <hr> produzieren zwei Horizontal Rulers.
Achtung mehrere Leerzeichen irritieren
Html genauso wenig wie
mehrere Leerzeilen.
wird.
Zwei
produzieren zwei Newlines. Es gibt auch noch das tag
--------------------------------------------------------------------------------
was einen Trenner darstellt. Zwei
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Html
genauso wenig wie mehrere Leerzeilen.
#include<iostream>
char s[];
using namespace std;
int main()
{
int count=;
while(~scanf("%s",s))
{
if(!strcmp(s,"<br>"))
{
cout<<endl;
count=;
}
else if(!strcmp(s,"<hr>"))
{
if(count)
cout<<'\n';
cout<<"--------------------------------------------------------------------------------\n";
count=;
}
else
{
int length=strlen(s);
if(count==)
{
cout<<s;
count=length;
}
else if((count+length+)>=)
{
cout<<endl<<s;
count=length;
}
else
{
cout<<' '<<s;
count+=length+;
}
}
}
cout<<endl;
}
1161.
composition, the writing length does not surpass 1000 characters.
#include<iostream>
const int maxn=;
char str[];
using namespace std;
int main()
{
while(gets(str))
{
for(int i=;str[i]!='\0';i++)
{
if(str[i]>='A'&&str[i]<='Z')
str[i]+=;
}
cout<<str<<endl;
}
}
1200.
t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x
Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ‘x’ to pad the message out to make a rectangle, although he could have used any letter.
Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as
toioynnkpheleaigshareconhtomesnlewx
Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
#include<iostream>
using namespace std;
#include<string>
int main()
{
// freopen("F:\\in.txt","r",stdin);
//freopen("F:\\ou.txt","w",stdout);
string s;int c,t,count;
while(){
cin>>c;
if(!c) break;
cin>>s;
int n=int(s.length());
for(int k=;k<=c;k++)
{
t=k-;count=;
while(t<=n-)
{
cout<<s[t];
if(count%)
t+=*c--*(k-);
else
t+=*k-;
count++;
}
}
cout<<endl;
}
//fclose(stdin);
//fclose(stdout);
return ;
}
2017.
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
9
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main()
{
int n,count;
cin>>n;
while(n--)
{
count=;
string str;
cin>>str;
for(string::iterator it=str.begin();it!=str.end();it++)
if(isdigit(*it))
count++;
cout<<count<<endl;
} }
HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)的更多相关文章
- hdu 5326(基础题) work
http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工 ...
- HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
双向边,基础题,最小生成树 题目 同题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...
- hdu 2089 不要62 (数位dp基础题)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Jam's balance HDU - 5616 (01背包基础题)
Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side ...
- 小试牛刀3之JavaScript基础题
JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...
- 小试牛刀2:JavaScript基础题
JavaScript基础题 1.网页中有个字符串“我有一个梦想”,使用JavaScript获取该字符串的长度,同时输出字符串最后两个字. 答案: <!DOCTYPE html PUBLIC &q ...
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...
- Java面试题以及答案精选(架构师面试题)-基础题1
基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...
- C/C++笔试题(基础题)
为了便于温故而知新,特于此整理 C/C++ 方面相关面试题.分享,共勉. (备注:各题的重要程度与先后顺序无关.不断更新中......欢迎补充) (1)分析下面程序的输出(* 与 -- 运算符优先级问 ...
随机推荐
- memcached使用文档
使用memcached进行内存缓存 通常的网页缓存方式有动态缓存和静态缓存等几种,在ASP.NET中已经可以实现对页面局部进行缓 存,而使用memcached的缓存比ASP.NET的局部缓存更加灵活, ...
- Swift开发常用知识点
#pragma mark - as/类型转换as? / as! 需要根据前面的返回值决定 有?证明可选,可能为空:需要弱解包 没有?证明一定有值:大胆解包 as? 前面的结果是可选的 if let / ...
- visual studio for mac在线安装网络错误
vs2017 for mac 终于出正式版了,兴冲冲的准备摆脱虚拟机. 官网https://www.visualstudio.com/zh-hans/vs/visual-studio-mac/下了安装 ...
- 《javascript高级程序设计》笔记七
第五章 引用类型(三) 今天首先说的就是Function类型.下面就是定义函数的两种方法,第一种使用函数声明语法定义,第二种使用函数表达式定义.这两种定义函数的方式几乎没有什么区别. function ...
- MinGW(GCC)编译DLL文件
这两天用CB(Code::Blocks)写个小程序,要编译出DLL供VB(6)使用.CB使用mingw-gcc作为编译器,在库文件的产出上跟VC.VS之类的IDE略有不同. 由于C语言的基础知识不是太 ...
- Chrome浏览器扩展开发系列之四:Browser Action类型的Chrome浏览器扩展
Browser Action类型的Google Chrome扩展程序,通常在Chrome浏览器的工具栏中,地址栏的右侧,有一个始终存在的图标.也就是说,这个图标与浏览器相关,只要安装了该Chrome扩 ...
- SQL Server分页查询方法整理
SQL Server数据库分页查询一直是SQL Server的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页 ...
- 64位Win10系统安装Mysql5.7.11
最近在装了64位Win10系统的mac book笔记本上用mysql-installer-community-5.7.11.0安装Mysql5.7.11,在配置mysql server时老是卡住,报错 ...
- 使用ajax提交form表单(转)
前言 使用ajax请求数据,很多人都会,比如说: $.post(path,{data:data},function(data){ ... },"json"); 又或者是这样的aja ...
- Microsoft office2010页码设置----论文、课程设计报告格式
思想:将目录页(含目录页)与目录页以下的页面用分隔符分隔开,单独设置目录页以下的页面页码,删除目录页(含目录)以前的页码. 1.在目录页页面内容最下面一行插入分隔符,实现与下面页面分隔开的目的. 页面 ...