1. 编写一个程序,以(555)5555-5555形式输入电话号码字符串。程序用函数strtno将电话号码字符串的区号和号码分开。电话号码的八位数连接成一个字符串。程序将区号字符串变为int型,将电话号码字符串变为long型,并打印区号和电话号码字符串。例如,从键盘上输入(027)8838-0000,则输出区号为27(int型),电话号码为88380000(long型)。
用C++语言写一个程序
答案:1 悬赏:30 手机版
解决时间 2021-05-02 22:58
- 提问者网友:活着好累
- 2021-05-02 12:19
最佳答案
- 五星知识达人网友:神的生死簿
- 2021-05-02 13:22
#include <iostream>
#include <string>
#include <utility>
using namespace std;
typedef pair<int, long> tel;
tel strtno( const string& s )
{
tel tmp;
tmp.first = atoi( s.substr( 1, 3 ).c_str() );
tmp.second = atol( ( s.substr( 5, 4 ) + s.substr( 10, 4 ) ).c_str() );
return tmp;
}
int main()
{
tel r = strtno( "(027)8838-0000" );
cout << r.first << endl;
cout << r.second << endl;
}
望采纳
#include <string>
#include <utility>
using namespace std;
typedef pair<int, long> tel;
tel strtno( const string& s )
{
tel tmp;
tmp.first = atoi( s.substr( 1, 3 ).c_str() );
tmp.second = atol( ( s.substr( 5, 4 ) + s.substr( 10, 4 ) ).c_str() );
return tmp;
}
int main()
{
tel r = strtno( "(027)8838-0000" );
cout << r.first << endl;
cout << r.second << endl;
}
望采纳
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯