算法竞赛入门经典第二版 第三章【uvaoj在线习题】Examples
来源:互联网 发布:偏爱说唱—网络歌手 编辑:程序博客网 时间:2024/04/29 08:28
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=828
Examples:
272 - TEX Quotes:
#include <stdio.h>int main(){int c,q = 1;while((c = getchar()) != EOF){if (c == '"'){printf("%s",q?"``":"''");q = !q;}else{printf("%c",c);}}return 0;}
10082 - WERTYU
#include <stdio.h>char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;\'ZXCVBNM,./";int main(){int i,c;while((c = getchar()) != EOF){for (i = 1;s[i] && s[i] != c;i++);if (s[i]){putchar(s[i-1]);} else{putchar(c);}}return 0;}
401 - Palindromes
#include <stdio.h>#include <string.h>//string.h大写UVA不识别,报Compilation error#include <ctype.h>const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";const char* msg[] = {"not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome"};char r(char ch){if (isalpha(ch)){return rev[ch - 'A'];}return rev[ch - '0' + 25];}int main(){char s[30];while(scanf("%s",s) == 1){int len = strlen(s);int p = 1,m = 1;for(int i = 0;i < (len + 1)/2;i++){if (s[i] != s[len - 1 - i]){p = 0;}if (r(s[i]) != s[len - 1- i]){m = 0;}}printf("%s -- is %s.\n\n",s,msg[m * 2 + p]);}return 0;}
340 - Master-Mind Hints 1
#include <stdio.h>#define maxn 1010int main(){int n,a[maxn],b[maxn];int kase = 0;while(scanf("%d",&n) == 1 && n){printf("Game %d:\n",++kase);for(int i = 0;i < n;i++)scanf("%d",&a[i]);for(;;){int A = 0,B = 0;for(int i = 0;i < n;i++){scanf("%d",&b[i]);if (a[i] == b[i]){A++;}}if (b[0] == 0){break;}for(int d = 1;d <= 9;d++){int c1 = 0,c2 = 0;for(int i = 0;i < n;i++){if (a[i] == d){c1++;}if (b[i] == d){c2++;}}if (c1 < c2){B += c1;}else{B += c2;}}printf(" (%d,%d)\n",A,B-A);}}return 0;}340 - Master-Mind Hints 2
#include <stdio.h>int main(){int i,j,f,n,A,B,a[1010],b[1010],c[1010],sum=0,num;while (scanf("%d",&n),n){++sum;printf("Game %d:\n",sum);for (i=1;i<=n;i++)scanf("%d",&a[i]);f=1;while (f){num=0;for (i=1;i<=n;i++){scanf("%d",&b[i]); c[i]=a[i]; if (b[i]==0) ++num; }if (num==n) break;A=0;B=0;for (i=1;i<=n;i++)if (c[i]==b[i]) {++A;c[i]=-1;b[i]=-1;}for (i=1;i<=n;i++){if (c[i]!=-1){for (j=1;j<=n;j++)if ((c[i]==b[j])) {++B;c[i]=-1;b[j]=-1;break;}}}printf(" (%d,%d)\n",A,B); }}return 0;}
1583 - Digit Generator
#include <stdio.h>#include <string.h>#define maxn 100005int ans[maxn];int main(){int T,n;memset(ans,0,sizeof(ans));for(int m = 1;m < maxn;m++){int x = m,y = m;while(x > 0){y += x % 10;x /= 10;}if (ans[y] == 0 || m < ans[y]){ans[y] = m;}}scanf("%d",&T);while(T--){scanf("%d",&n);printf("%d\n",ans[n]);}return 0;}
1584 - Circular Sequence
#include <stdio.h>#include <string.h>#define maxn 105int less(const char* s,int p,int q){int n = strlen(s);for (int i = 0;i < n;i++){if (s[(p+i) % n] != s[(q + i) % n]){return s[(p + i) % n] < s[(q + i) % n];}}return 0;}int main(){int T;char s[maxn];scanf("%d",&T);while(T--){scanf("%s",s);int ans = 0;int n = strlen(s);for(int i = 1;i < n;i++){if (less(s,i,ans)){ans = i;}}for(int i = 0;i < n;i++)//VC6.0显示重定义,但UVA上若无int会导致编译错误{putchar(s[(i + ans) % n]);}putchar('\n');}return 0;}
0 0
- 算法竞赛入门经典第二版 第三章【uvaoj在线习题】Examples
- 算法竞赛入门经典第二版 第三章【uvaoj在线习题】Exercises
- 【算法竞赛入门经典第二版学习】第三章习题
- 算法竞赛入门经典第二版第三章习题
- 算法竞赛入门经典第四章 【uvaoj在线习题(二)】
- 算法竞赛入门经典第二章习题
- 算法竞赛入门经典习题 第二章
- 算法竞赛经典入门第三章习题
- 算法竞赛入门经典习题 第三章
- 《算法竞赛入门经典(第二版)》第三章 习题(1-5)
- 《算法竞赛入门经典(第二版)》第三章 习题(6-9)
- 算法竞赛入门经典(第二版)第三章课后习题(1-4)未完待续
- 算法竞赛入门经典第二版 第三章
- 【算法竞赛入门经典】【第三章】课后习题(第二部分)
- 算法竞赛入门经典(第二版)-刘汝佳-第三章 数组与字符串 例题+习题(17/18)
- 算法竞赛入门经典第4章 【uvaoj习题(一)】
- 算法竞赛入门经典(第二版) 习题训练
- 算法竞赛入门经典(第二版) 习题
- C++文件操作:fstream类
- 安装MySQL,添加用户
- js设计模式之装饰模式
- Darwin Streaming Server for Windows 安装
- session机制
- 算法竞赛入门经典第二版 第三章【uvaoj在线习题】Examples
- printf函数
- 几个常见的语音交互平台的简介和比较
- ordereddict can't import
- Shell脚本: Windows下可用源码 转换为 Linux下可用源码
- 概率dp题,掷骰子
- 30 eclipce 创建模板
- ObjectARX各个版本下载
- ImageView实现适屏和裁剪图片的功能