HDOJ 1075:
给出单词对应表,将给出的句子翻译过来。
代码:
1 #include "cstdio" 2 #include "stdlib.h" 3 #include "iostream" 4 #include "algorithm" 5 #include "string" 6 #include "cstring" 7 #include "queue" 8 #include "cmath" 9 #include "vector" 10 #include "map" 11 #include "set" 12 #define db double 13 #define ll long long 14 #define inf 0x3f3f3f 15 using namespace std; 16 const int N=1e6+2; 17 const int mod=1e9+7; 18 char s[N],t[N]; 19 char word[20]; 20 string f,k; 21 map<string,string> mp; 22 map<string,string>::iterator it; 23 int main() 24 { 25 scanf("%s",s); 26 while(scanf("%s",s)==1&&strcmp(s,"END")!=0){ 27 scanf("%s",t); 28 f=s; 29 mp[t]=f; 30 31 } 32 scanf("%s\n",s); 33 while(gets(s)&&strcmp(s,"END")!=0){ 34 int n=strlen(s); 35 for(int i=0,j=0;i<n;i++){ 36 if(s[i]>='a'&&s[i]<='z') 37 word[j++]=s[i]; 38 else 39 { 40 if(j){ 41 word[j++]='\0'; 42 k=word; 43 if(mp.count(k)){ 44 printf("%s",mp[k].c_str()); 45 } 46 else printf("%s",word); 47 j=0; 48 } 49 printf("%c",s[i]); 50 } 51 } 52 puts(""); 53 } 54 55 56 }
HDOJ 1088:
将凌乱的网页文字按要求整合好。
代码:
1 #include "cstdio" 2 #include "stdlib.h" 3 #include "iostream" 4 #include "algorithm" 5 #include "string" 6 #include "cstring" 7 #include "queue" 8 #include "cmath" 9 #include "vector" 10 #include "map" 11 #include "set" 12 #define db double 13 #define ll long long 14 #define inf 0x3f3f3f 15 using namespace std; 16 const int N=1e6+2; 17 const int mod=1e9+7; 18 char s[100],t[N]; 19 char word[20]; 20 string f,k; 21 int main() 22 { 23 int ans=0; 24 while(scanf("%s",s)!=EOF) 25 { 26 if(!strcmp(s,"<br>")){ 27 puts(""); 28 ans=0; 29 } 30 else if(!strcmp(s,"<hr>")){ 31 if(ans!=0) puts(""); 32 puts("--------------------------------------------------------------------------------"); 33 ans=0; 34 } 35 else 36 { 37 if((ans!=0&&ans+strlen(s)+1<=80)||!ans&&strlen(s)<=80){ 38 if(!ans) printf("%s",s),ans+=strlen(s); 39 else printf(" %s",s),ans+=strlen(s)+1; 40 // ans+=strlen(s)+1; 41 } 42 else { 43 puts(""); 44 printf("%s",s); 45 ans=strlen(s); 46 } 47 } 48 49 } 50 puts(""); 51 52 return 0; 53 }
HDOJ 1113:
给出一个单词表,再给一些单词,将与其单词组成相同的单词表单词输出。
代码:
1 #include "cstdio" 2 #include "iostream" 3 #include "algorithm" 4 #include "string" 5 #include "cstring" 6 #include "queue" 7 #include "cmath" 8 #include "vector" 9 #include "map" 10 #include "stdlib.h" 11 #include "set" 12 #define mj 13 #define db double 14 #define ll long long 15 using namespace std; 16 const int N=1e4+5; 17 const int mod=1e9+7; 18 const ll inf=1e16+10; 19 char s[30]; 20 map<string,string> mp; 21 string k; 22 int main() 23 { 24 int cnt=0; 25 while(scanf("%s",s)==1&&strcmp(s,"XXXXXX")!=0){ 26 a[cnt]=s; 27 k=s; 28 sort(k.begin(),k.end());//将单词内的字母排序 29 mp[s]=k; 30 } 31 32 while(scanf("%s",s)==1&&strcmp(s,"XXXXXX")!=0){ 33 k=s; 34 sort(k.begin(),k.end()); 35 map<string,string>::iterator it; 36 bool ok=0; 37 for(it=mp.begin();it!=mp.end();it++){ 38 if(it->second==k){ 39 cout<<it->first<<endl; 40 ok=1; 41 } 42 } 43 if(!ok) puts("NOT A VALID WORD"); 44 puts("******"); 45 } 46 47 }
HDOJ 1200
将一个蛇形的字符串,按列从小到大输出。
代码:
1 #include "cstdio" 2 #include "stdlib.h" 3 #include "iostream" 4 #include "algorithm" 5 #include "string" 6 #include "cstring" 7 #include "queue" 8 #include "cmath" 9 #include "vector" 10 #include "map" 11 #include "set" 12 #define db double 13 #define ll long long 14 #define inf 0x3f3f3f 15 using namespace std; 16 const int N=1e6+2; 17 const int mod=1e9+7; 18 char s[500],t[500]; 19 char word[20]; 20 string f,k; 21 int main() 22 { 23 int n; 24 while(scanf("%d",&n)==1&&n!=0) 25 { 26 memset(t,'\0', sizeof(t)); 27 scanf("%s",s+1); 28 int l=strlen(s+1); 29 int x=l/n; 30 for(int i=1;i<=x;i+=2){ 31 int v=i*n+1,vv=(i+1)*n; 32 char ss; 33 for(int j=v;j<=(vv+v)/2;j++) 34 ss=s[j],s[j]=s[vv+v-j],s[vv+v-j]=ss; 35 } 36 int p=0; 37 for(int i=1;i<n;i++){ 38 for(int j=1;j<=l;j++){ 39 if(j%n==i){ 40 t[p++]=s[j]; 41 } 42 } 43 } 44 for(int j=1;j<=l;j++) 45 if(j%n==0) t[p++]=s[j]; 46 puts(t); 47 } 48 }
HDOJ 1256
按要求输出 用字母组成的数字8 PS:每行后面无空格!
1 #include "cstdio" 2 #include "stdlib.h" 3 #include "iostream" 4 #include "algorithm" 5 #include "string" 6 #include "cstring" 7 #include "queue" 8 #include "cmath" 9 #include "vector" 10 #include "map" 11 #include "set" 12 #define db double 13 #define ll long long 14 #define inf 0x3f3f3f 15 using namespace std; 16 const int N=1e6+2; 17 const int mod=1e9+7; 18 char s[100],t[N]; 19 char word[20]; 20 string f,k; 21 int main() 22 { 23 int t,x; 24 int ans; 25 scanf("%d",&t); 26 int cnt=1; 27 for(int ii=1;ii<=t;ii++) 28 { 29 getchar(); 30 char e; 31 scanf("%c %d",&e,&x); 32 ans=x/6+1; 33 x-=3; 34 int x1=x/2,x2=x-x1; 35 for(int i=1;i<=x2+ans;i++){ 36 if(i>=ans+1&&i<=x2+ans) 37 printf("%c",e); 38 else printf(" "); 39 } 40 puts(""); 41 for(int i=0;i<x1;i++){ 42 for(int j=1;j<=x2+2*ans;j++) 43 if(j>=ans+1&&j<=x2+ans) 44 printf(" "); 45 else printf("%c",e); 46 puts(""); 47 } 48 for(int i=1;i<=x2+ans;i++){ 49 if(i>=ans+1&&i<=x2+ans) 50 printf("%c",e); 51 else printf(" "); 52 } 53 puts(""); 54 for(int i=0;i<x2;i++){ 55 for(int j=1;j<=x2+2*ans;j++) 56 if(j>=ans+1&&j<=x2+ans) 57 printf(" "); 58 else printf("%c",e); 59 puts(""); 60 } 61 for(int i=1;i<=x2+ans;i++){ 62 if(i>=ans+1&&i<=x2+ans) 63 printf("%c",e); 64 else printf(" "); 65 } 66 puts(""); 67 if(ii!=t) puts(""); 68 } 69 return 0; 70 }
HDOJ 2206
题意:判断给出的IP是否合法。(很多坑!)
代码:
1 #include<bits/stdc++.h> 2 #define db double 3 #define ll long long 4 using namespace std; 5 const int N=1e6+5; 6 const int mod=1e9+7; 7 char s[N]; 8 int p[N]; 9 int main() 10 { 11 while(gets(s)!=NULL) 12 { 13 int cnt=0; 14 bool ok=1; 15 for(int i=0;s[i];i++) 16 { 17 if(s[i]=='.') p[cnt++]=i; 18 if(!(s[i]=='.'||(s[i]>='0'&&s[i]<='9'))) ok=0;//非法字符 19 } 20 if(p[0]>=4||p[0]==0) ok=0;//第一个.不能在第一位或第三位以后 21 if(cnt!=3) ok=0;//.数量不等于3 22 for(int i=1;i<=2;i++) 23 { 24 int t=p[i]-p[i-1]; 25 if(t>4||t==0) ok=0;//中间数字长度0<L<=4 26 } 27 int c=0; 28 for(int i=0;s[i];i++)//所有出现的数字小于等于255 29 if(s[i]!='.') c=c*10+s[i]-'0'; 30 else if(c>255) ok=0; 31 else c=0; 32 if(c>255) ok=0; 33 if(ok) printf("YES\n"); 34 else printf("NO\n"); 35 } 36 return 0; 37 }
HDOJ 2572
题意:给出三个字符串s1,s2,s3,求s1的一个最小字典序子串t,满足s2,s3都为其字串。
思路:先将s2,s3整合,去重,排序,判断是否为s1的字串,若是输出,否则无解。
代码:
1 #include "cstdio" 2 #include "algorithm" 3 #include "iostream" 4 #include "string" 5 #include "cstring" 6 #include "queue" 7 #include "cmath" 8 #include "vector" 9 #include "map" 10 #include "set" 11 #define db double 12 #define inf 0x3f3f3f 13 typedef long long ll; 14 using namespace std; 15 const int N=1e6+5; 16 int t; 17 char s[N],ss[N]; 18 int a[200],b[200]; 19 string f,k,d,tt; 20 set<char> all; 21 map<char,int> mp,mm; 22 int main() 23 { int T,i,j,n; 24 cin>>T; 25 while(T--) 26 { 27 string s,s1,s2,s3,str; //str起临时存储的作用 28 cin>>s1>>s2>>s3; 29 n=s1.length(); 30 // sort(s1.begin(),s1.end()); 31 str=s1+"#"; 32 33 for(i=0; i<n; i++) 34 { 35 for(j=i+1; j<=n; j++) 36 { 37 s=s1.substr(i,j-i); //substr是C++语言函数,主要功能是复制子字符串,要求从指定位置开始,并具有指定的长度。 38 if(s.find(s2)!=-1&&s.find(s3)!=-1) //未找到s2、s3则返回-1 39 { 40 if(s.length()<str.length()) str=s; 41 42 else if(s.length()==str.length()) 43 { 44 if(s<str) str=s; 45 } 46 } 47 } 48 } 49 if(str.length()==n+1) cout<<"No"<<endl; 50 else cout<<str<<endl; 51 } 52 return 0; 53 }