zoukankan      html  css  js  c++  java
  • 1005 Spell It Right

    本程序为PAT A1002 Spell It Right 答案,题目链接

    主体思想:将输入的整数型转化为字符串类型,从而分割出每一位的值,将他们加和,加和后的结果仍然需要“分割”,因此再转化为字符串。

    注意:

      英语单词要拼写正确;

      最后一位输出无空格;

    程序代码:

     1 #include "pch.h"
     2 #include <iostream>
     3 #include <string>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     string a,s;
     9     string spill[10] = { "zero", "one","two","three","four","five","six","seven","eight","nine" };
    10     cin>>a;
    11     int sum = 0;
    12     for (int i = 0; i < a.length(); i++) {
    13         sum += a[i]-'0';
    14     }
    15     s = to_string(sum);
    16     cout << spill[s[0] - '0'];
    17     for (int i = 1; i < s.length(); i++) {
    18         cout << ' '<< spill[s[i]-'0'] ;
    19     }
    20     return 0;
    21 }

    提交结果:

  • 相关阅读:
    稠密光流
    分水岭分割
    Haar小波分析
    内积空间
    矩阵LU分解
    opencv笔记---contours
    Deformable Templates For Eye Detection
    最小二乘法
    字符集及编码
    层次聚类
  • 原文地址:https://www.cnblogs.com/qujunhui/p/10903450.html
Copyright © 2011-2022 走看看