| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
萌新530B的奇葩代码 字符串水题思路先把所有可简化的字符串写出来 比如!!简化为没有 (V)简化成V 然后每读一个非空格字符 都扫描一次其后缀是否是可化简的字符串 是就化简 读到EOF或者\n就输出整个字符串就好 显然合法的输入一定可以化简成F或V
有个坑点是最后一个输入似乎结尾是EOF不是\n
#include<stdio.h>
#include<string.h>
int i,j,q,z,k,w=1;
char c,a[105],s[13][2][4]={"(V)","V","(F)","F","!!","","!V","F","!F","V","V|V","V","V&V","V","F|F","F","F&F","F","V|F","V","V&F","F","F|V","V","F&V","F"};
int main()
{ while (scanf("%c",&c)!= EOF)
{i=0;
if (c!=32) a[i++]=c;
while (scanf("%c",&c)!=EOF&& c!=10)
{ if (c!=32) a[i++]=c;
for (j=0;j<13;j++)
{ q=strlen(s[j][0]),k = 0;
while (a[i-q+k]==s[j][0][k]) k++;
if (k>=q) strcpy(a+i-q,s[j][1]),i+=strlen(s[j][1])-q; }}
printf("Expression %d: %s\n",w++,a);
}}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator