山东省第三届省赛 (Pixel density)

字符串处理

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <sstream>
#include <cctype>
#include <string>
#define mem(a, val) memset((a), (val), sizeof (a))
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long LL;
const int maxn = 10100;
string str[maxn];
double x;
int y,z,kase=1;
void print_ans(int i){
  double res = (x==0 ? 0:sqrt((y*y+z*z)*1.0 )/x);
  printf("Case %d: ",kase++);
  printf("The %s of",str[i+1].c_str());
  for(int j=0;j<i-1;j++) printf(" %s",str[j].c_str());
  printf("'s PPI is %.2lf.\n",res);
}
int main()
{
   int T;
   scanf("%d",&T);
   char src[maxn],c;
   gets(src);
   while(T--){
        cin.getline(src,1000,'\n');
        stringstream ss(src);
        for(int i=0;;i++){
             ss>>str[i];
             if(str[i]=="inches"){
                 x = atof(str[i-1].c_str());
                 ss>>y>>c>>z;
                 ss>>str[i+1];
                 for(int j=0;j<str[i+1].length();j++)
                     if(isupper(str[i+1][j])) str[i+1][j]+='a'-'A';
                 print_ans(i);
                 break;
             }
        }
   }
   return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值