poj 3095(水题)
作者:互联网
#include<iostream> #include<cmath> #include<cstring> using namespace std; int main(){ char a[80],d[]={'/','\\','.','|','_'}; int len; double sum; while(scanf("%s",a)==1&&strcmp(a,"#")){ len = strlen(a); sum = 0; for(int i=0;i<len;i++){ if(a[i]=='_'){ sum += 1; } if(a[i]=='|'){ for(int j=i-1;j>-1;j--){ if(a[j]=='.')break; else if(a[j]=='|'||a[j]=='\\'){ sum += 0.5; break; } } for(int j=i+1;j<len;j++){ if(a[j]=='.')break; else if(a[j]=='|'||a[j]=='/'){ sum += 0.5; break; } } } if(a[i]=='/'){ for(int j=i-1;j>-1;j--){ if(a[j]=='.')break; else if(a[j]=='|'||a[j]=='\\'){ sum += 1; break; } } } if(a[i]=='\\'){ for(int j=i+1;j<len;j++){ if(a[j]=='.')break; else if(a[j]=='|'||a[j]=='/'){ sum += 1; break; } } } } printf("%.0lf\n",floor(100-100.0*sum/len)); } return 0; }
标签:水题,int,sum,len,else,break,poj,3095,include 来源: https://www.cnblogs.com/stevenzrx/p/15647055.html