• 天梯赛 L1_33 出生年


      在这一题中主要考虑到字符串与整数之间的相互转换

      字符串转换为整数   

            string s="123456";

       int n=atoi(s.c_str());  //string头文件下

      整数转换字符串

           int n=123;

           string s;

           stringstream ss;

           ss<<n;

           ss>>s;  //在stringstream头文件下

     一下为源代码

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<string>
     4 #include<sstream>
     5 using namespace std;
     6 int main()
     7 {
     8     bool A[10];
     9     string s;
    10     int n,num,num1;
    11     cin>>s>>n;
    12     num=atoi(s.c_str());
    13     num1=num;
    14     for(;; num1++)
    15     {
    16         stringstream ss;
    17         ss << num1;
    18         ss >> s;
    19         while(s.length()!=4)
    20         {
    21             s='0'+s;
    22         }
    23         for(int i=0; i<10; i++)
    24         {
    25             A[i]=false;
    26         }
    27         int flag=0;
    28         for(int i=0; i<s.length(); i++)
    29         {
    30             int m=s[i]-'0';
    31             for(int j=0; j<10; j++)
    32             {
    33                 if(!A[m])
    34                 {
    35                     flag++;
    36                     A[m]=true;
    37                 }
    38             }
    39         }
    40         if(flag==n)
    41         {
    42             break;
    43         }
    44     }
    45     cout<<(num1-num)<<" "<<s<<endl;
    46 }
  • 相关阅读:
    Vue常见问题总结
    vue学习记录
    内卷
    at least once 和 at most once 问题
    IO学习笔记(全)
    IO学习笔记7
    IO学习笔记6
    IO学习笔记5
    IO学习笔记4
    IO学习笔记3
  • 原文地址:https://www.cnblogs.com/Yinchen-One/p/8510653.html
Copyright © 2020-2023  润新知