#include<bits/stdc++.h> using namespace std; string str,str1,str2,str3; string ff[9],aa; long long a=0,word[6]={0},out=0; int function(string s,long long &c) { if(s=="one"||s=="a"||s=="first"||s=="another"){word[c]=1;c++;return 0;} if(s=="two"||s=="both"||s=="second"){word[c]=4;c++;return 0;} if(s=="three"||s=="third"){word[c]=9;c++;return 0;} if(s=="four"){word[c]=16;c++;return 0;} if(s=="five"){word[c]=25;c++;return 0;} if(s=="six"){word[c]=36;c++;return 0;} if(s=="seven"){word[c]=49;c++;return 0;} if(s=="eight"){word[c]=64;c++;return 0;} if(s=="nine"){word[c]=81;c++;return 0;} if(s=="eleven"){word[c]=21;c++;return 0;} if(s=="twelve"){word[c]=44;c++;return 0;} if(s=="thirteen"){word[c]=69;c++;return 0;} if(s=="fourteen"){word[c]=96;c++;return 0;} if(s=="fifteen"){word[c]=25;c++;return 0;} if(s=="sixteen"){word[c]=56;c++;return 0;} if(s=="seventeen"){word[c]=89;c++;return 0;} if(s=="eightteen"){word[c]=24;c++;return 0;} if(s=="nineteen"){word[c]=61;c++;return 0;} } int main() { for(int i=0; i<6; i++) { cin>>ff[i]; if (ff[i][ff[i].size()-1]=='.') ff[i].erase(ff[i].size()-1,1); function(ff[i],a); } sort(word,word+a); for(int i=0; i<a; i++) { out+=word[i]; out*=100; } cout<<out/100; return 0; }
时间: 2024-04-28 07:25:45 浏览: 16
这段代码的功能是将输入的字符串中的数字转换为对应的平方数,然后将这些平方数按照从小到大的顺序排列,并输出它们组成的整数。具体实现是通过一个函数来判断每个字符串是否对应一个数字,如果是,则将其转换成平方数,并存储到一个数组中。最后,将数组排序,然后将其中的平方数按顺序组成一个整数输出。
需要注意的是,这段代码可能存在一些问题,比如输入的字符串中可能存在多余的空格或标点符号,可能会影响字符串的判断和转换。此外,该程序中的平方数转换方式也并非完全正确,比如 "fifteen" 对应的平方数应该是 225 而不是 25。
相关问题
#include <bits/stdc++.h> using namespace std
这段代码是一个C++的头文件引用和命名空间的使用示例。具体来说,`#include <bits/stdc++.h>`是一个常用的头文件引用方式,它包含了C++标准库中的所有头文件。而`using namespace std`则是为了使用`std`命名空间中的标准库函数和对象,这样就可以直接使用`cout`、`cin`等标准输入输出流对象,而不需要写`std::cout`、`std::cin`。
这种写法虽然方便,但也存在一些问题。首先,包含了所有的标准库头文件可能会导致编译时间变长。其次,使用了`using namespace std`会将整个`std`命名空间中的所有标识符引入当前作用域,可能会导致命名冲突。因此,在实际开发中,建议根据需要只包含需要的头文件,并使用具体的命名空间来避免潜在的问题。
#include <bits/stdc++.h> using namespace std;
这个头文件是C++11标准引入的,它包含了所有标准库中的头文件。使用这个头文件可以方便地在一个地方包含所有需要的头文件,而不需要一个一个地包含。这个头文件通常只在竞赛中使用,因为它不是标准C++头文件,不保证在所有编译器中都能正常工作。
以下是一个使用这个头文件的示例,实现输入4个整数a、b、c、d,将它们倒序输出:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << d << ' ' << c << ' ' << b << ' ' << a << endl;
return 0;
}
```
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![h](https://img-home.csdnimg.cn/images/20210720083646.png)
![h](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)