<C/C++算法>九度OJ题目1151--1200解题练习(五)

From:http://blog.csdn.net/ebowtang/article/details/38277903


题目1151:位操作练习

题目描述:

给出两个不大于65535的非负整数,判断其中一个的16位二进制表示形式,是否能由另一个的16位二进制表示形式经过循环左移若干位而得到。

循环左移和普通左移的区别在于:最左边的那一位经过循环左移一位后就会被移到最右边去。比如:
1011 0000 0000 0001 经过循环左移一位后,变成 0110 0000 0000 0011, 若是循环左移2位,则变成 1100 0000 0000 0110

输入:

第一行是个整数n, 0 < n < 300000,表示后面还有n行数据
后面是n行,每行有两个不大于65535的非负整数

输出:

对于每一行的两个整数,输出一行,内容为YES或NO

样例输入:
4
2 4
9 18
45057 49158
7 12
样例输出:
YES
YES
YES
NO


题目1153:括号匹配问题

题目描述:

在某个字符串(长度不超过100)中有左括号、右括号和大小写字母;规定(与常见的算数式子一样)任何一个左括号都从内到外与在它右边且距离最近的右括号匹配。写一个程序,找到无法匹配的左括号和右括号,输出原来字符串,并在下一行标出不能匹配的括号。不能匹配的左括号用"$"标注,不能匹配的右括号用"?"标注.

输入:

输入包括多组数据,每组数据一行,包含一个字符串,只包含左右括号和大小写字母,字符串长度不超过100。
注意:cin.getline(str,100)最多只能输入99个字符!

输出:

对每组输出数据,输出两行,第一行包含原始输入字符,第二行由"$","?"和空格组成,"$"和"?"表示与之对应的左括号和右括号不能匹配。

样例输入:
)(rttyy())sss)(
样例输出:
)(rttyy())sss)(
?            ?$

  1. #include "iostream"
  2. #include "string"
  3. #include "stack"
  4. using namespace std;
  5. void BracketMatch(const string srcStr);
  6. int main()
  7. {
  8. string str;
  9. while (cin >> str)
  10. {
  11. cout << str << endl;
  12. BracketMatch(str);
  13. }
  14. return 0;
  15. }
  16. void BracketMatch(const string srcStr)
  17. {
  18. stack<int> s;
  19. string ansStr(srcStr.length(),'0');
  20. for (unsigned int i = 0; i < srcStr.length(); i++)//从左往右开始遍历
  21. {
  22. if (isalpha(srcStr[i]))
  23. {
  24. ansStr[i]=' ';
  25. continue;
  26. }
  27. switch (srcStr[i])
  28. {
  29. //对左括号仅作压栈处理,也就是说栈中只可能是左括号
  30. case '(':
  31. if (i != (srcStr.length() - 1))//当是最后一个字符时已经没有必要输出空格了
  32. ansStr[i] = ' ';
  33. s.push(i);//注意,这里
  34. break;
  35. //对右括号做匹配判断
  36. case ')':
  37. if (!s.empty())
  38. {//如果不为空,说明一定有左括号(实际上是其数组下标)
  39. s.pop();
  40. ansStr[i] = ' ';
  41. }
  42. else//如果为空
  43. ansStr[i] = '?';
  44. break;
  45. default:
  46. cerr << "错误的括号" << endl;
  47. }
  48. }
  49. while (!s.empty())
  50. { //解决多余的左括号
  51. ansStr[s.top()] = '$';
  52. s.pop();
  53. }
  54. cout << ansStr << endl;
  55. }
  56. /**************************************************************
  57. Problem: 1153
  58. User: EbowTang
  59. Language: C++
  60. Result: Accepted
  61. Time:10 ms
  62. Memory:1524 kb
  63. ****************************************************************/
#include "iostream"  
#include "string"  
#include "stack"  
 
using namespace std;
 
void BracketMatch(const string srcStr);
int main()
{
    string str;
    while (cin >> str)
    {
        cout << str << endl;
        BracketMatch(str);
    }
    return 0;
}
 
void BracketMatch(const string srcStr)
{
    stack<int> s;
    string ansStr(srcStr.length(),'0');
    for (unsigned int i = 0; i < srcStr.length(); i++)//从左往右开始遍历  
    {
        if (isalpha(srcStr[i]))
        {
            ansStr[i]=' ';
            continue;
        }
        switch (srcStr[i])
        {
                //对左括号仅作压栈处理,也就是说栈中只可能是左括号  
            case '(':
                if (i != (srcStr.length() - 1))//当是最后一个字符时已经没有必要输出空格了
                    ansStr[i] = ' ';
                s.push(i);//注意,这里
                break;
 
                //对右括号做匹配判断
            case ')':
                if (!s.empty())
                {//如果不为空,说明一定有左括号(实际上是其数组下标)
                    s.pop();
                    ansStr[i] = ' ';
                }
                else//如果为空
                    ansStr[i] = '?';
                break;
 
            default:
                cerr << "错误的括号" << endl;
        }
    }
    while (!s.empty())
    {  //解决多余的左括号  
        ansStr[s.top()] = '$';
        s.pop();
    }
    cout << ansStr << endl;
}
/**************************************************************
    Problem: 1153
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1524 kb
****************************************************************/


题目1156:谁是你的潜在朋友

题目描述:

“臭味相投”——这是我们描述朋友时喜欢用的词汇。两个人是朋友通常意味着他们存在着许多共同的兴趣。然而作为一个宅男,你发现自己与他人相互了解的机会并不太多。幸运的是,你意外得到了一份北大图书馆的图书借阅记录,于是你挑灯熬夜地编程,想从中发现潜在的朋友。
首先你对借阅记录进行了一番整理,把N个读者依次编号为1,2,…,N,把M本书依次编号为1,2,…,M。同时,按照“臭味相投”的原则,和你喜欢读同一本书的人,就是你的潜在朋友。你现在的任务是从这份借阅记录中计算出每个人有几个潜在朋友。

输入:

每个案例第一行两个整数N,M,2 <= N ,M<= 200。接下来有N行,第i(i = 1,2,…,N)行每一行有一个数,表示读者i-1最喜欢的图书的编号P(1<=P<=M)

输出:

每个案例包括N行,每行一个数,第i行的数表示读者i有几个潜在朋友。如果i和任何人都没有共同喜欢的书,则输出“BeiJu”(即悲剧,^ ^)

样例输入:
4  5
2
3
2
1
样例输出:
1
BeiJu
1
BeiJu
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int findK(int key,int A[],int s,int n){
  5. int count = 1;
  6. for (int i = s + 1; i < n; i++){
  7. if (A[i]==key){
  8. count++;
  9. }
  10. }
  11. return count;
  12. }
  13. int pCount[200];
  14. int f[1000];
  15. int main(){
  16. int N, M;
  17. int key;
  18. while (cin >> N >> M){
  19. memset(pCount, 0, 200 * sizeof(int));
  20. for (int i = 0; i < N; i++){
  21. cin >> key;
  22. pCount[key]++;
  23. f[i] = key;
  24. }
  25. for (int i = 0; i < N; i++){
  26. key = f[i];
  27. if (pCount[key] == 1)
  28. cout << "BeiJu" << endl;
  29. else
  30. cout << pCount[key]-1<< endl;
  31. }
  32. }
  33. return 0;
  34. }
  35. /**************************************************************
  36. Problem: 1156
  37. User: EbowTang
  38. Language: C++
  39. Result: Accepted
  40. Time:10 ms
  41. Memory:1524 kb
  42. ****************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
 
int findK(int key,int A[],int s,int n){
    int count = 1;
    for (int i = s + 1; i < n; i++){
        if (A[i]==key){
            count++;
        }
    }
    return count;
}
 
int pCount[200];
 
int f[1000];
 
int main(){
 
     
    int N, M;
    int key;
    while (cin >> N >> M){
        memset(pCount, 0, 200 * sizeof(int));
        for (int i = 0; i < N; i++){
            cin >> key;
            pCount[key]++;
            f[i] = key;
        }
        for (int i = 0; i < N; i++){
            key = f[i];
            if (pCount[key] == 1)
                cout << "BeiJu" << endl;
            else
                cout << pCount[key]-1<< endl;
        }
    }
 
 
    return 0;
}
/**************************************************************
    Problem: 1156
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1524 kb
****************************************************************/


题目1169:比较奇偶数个数

题目描述:

第一行输入一个数,为n,第二行输入n个数,这n个数中,如果偶数比奇数多,输出NO,否则输出YES。

输入:

输入有多组数据。
每组输入n,然后输入n个整数(1<=n<=1000)。

输出:

如果偶数比奇数多,输出NO,否则输出YES。

样例输入:
5
1 5 2 4 3
样例输出:
YES
  1. #include "vector"
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int n = 0;
  7. while (cin >> n)
  8. {
  9. vector<int> vec(n);
  10. int count = 0;
  11. for (int i = 0; i < n; i++)
  12. {
  13. cin >> vec[i];
  14. if (vec[i] % 2 == 1)
  15. count++;
  16. }
  17. if (count < (n - count))
  18. cout << "NO" << endl;
  19. else
  20. cout << "YES" << endl;
  21. }
  22. return 0;
  23. }
  24. /**************************************************************
  25. Problem: 1169
  26. User: EbowTang
  27. Language: C++
  28. Result: Accepted
  29. Time:10 ms
  30. Memory:1520 kb
  31. ****************************************************************/

题目1170:找最小数

题目描述:

第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。

输入:

输入有多组数据。
每组输入n,然后输入n个整数对。

输出:

输出最小的整数对。

样例输入:
5  
3 3  
2 2  
5 5  
2 1  
3 6
样例输出:
2 1
  1. #include <iostream>
  2. #include "algorithm"
  3. using namespace std;
  4. typedef struct _Point
  5. {
  6. int x;
  7. int y;
  8. }Point;
  9. bool cmpPoint(Point a, Point b)
  10. {
  11. if (a.x != b.x)
  12. return a.x < b.x;
  13. else
  14. return a.y<b.y;
  15. }
  16. int main(void)
  17. {
  18. int n = 0;
  19. while (cin>>n)
  20. {
  21. Point w[1000];
  22. for (size_t i = 0; i < n; i++)
  23. cin >> w[i].x >> w[i].y;
  24. //多关键字排序
  25. sort(w, w + n, cmpPoint);//功能是先排x,若相等则在其基础上对y进行排序。
  26. //输出最小点
  27. cout << w[0].x << " " << w[0].y << endl;
  28. }
  29. return 0;
  30. }
  31. /**************************************************************
  32. Problem: 1170
  33. User: EbowTang
  34. Language: C++
  35. Result: Accepted
  36. Time:10 ms
  37. Memory:1520 kb
  38. ****************************************************************/
#include <iostream>
#include "algorithm"
 
using namespace std;
 
typedef struct _Point
{
    int x;
    int y;
}Point;
 
bool cmpPoint(Point a, Point b)
{
    if (a.x != b.x)
        return a.x < b.x;
    else
        return a.y<b.y;
}
 
int main(void)
{
    int n = 0;
    while (cin>>n)
    {
        Point w[1000];
        for (size_t i = 0; i < n; i++)
            cin >> w[i].x >> w[i].y;
        //多关键字排序
        sort(w, w + n, cmpPoint);//功能是先排x,若相等则在其基础上对y进行排序。
        //输出最小点
        cout << w[0].x << " " << w[0].y << endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1170
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/

题目1180:对称矩阵

题目描述:

输入一个N维矩阵,判断是否对称。

输入:

输入第一行包括一个数:N(1<=N<=100),表示矩阵的维数。
接下来的N行,每行包括N个数,表示N*N矩阵的元素。

输出:

可能有多组测试数据,对于每组数据,
输出"Yes!”表示矩阵为对称矩阵。
输出"No!”表示矩阵不是对称矩阵。

样例输入:
4
16 19 16 6 
19 16 14 5 
16 14 16 3 
6 5 3 16 
2
1 2
3 4
样例输出:
Yes!
No!
  1. #include <iostream>
  2. #include "algorithm"
  3. using namespace std;
  4. int main()
  5. {
  6. int n = 0;
  7. while (cin>>n)
  8. {
  9. //vector<vector<int>> array(n);//定义二维数组
  10. //for (int i = 0; i <n; i++)
  11. // array[i].resize(n);//注意:必须设置二维数组的列数,即每一行有多少个元素
  12. //array[2][1] = 12;//将第三行的第二个元素初始化为12
  13. int **array=new int*[n];
  14. for (int i = 0; i < n; i++)
  15. array[i] = new int[n];
  16. for (int i = 0; i < n; i++)
  17. {
  18. for (int j = 0; j < n; j++)
  19. {
  20. cin >> array[i][j];//一行一行获取数据
  21. }
  22. }
  23. bool flag = false;
  24. for (int i = 0; i < n; i++)
  25. {
  26. for (int j = 0; j < n; j++)
  27. {
  28. if (array[i][j] != array[j][i])//对称的位置上必须相等
  29. flag = true;
  30. }
  31. if (flag)
  32. break;
  33. }
  34. if (flag)
  35. cout << "No!" << endl;
  36. else
  37. cout << "Yes!" << endl;
  38. }
  39. }
  40. /**************************************************************
  41. Problem: 1180
  42. User: EbowTang
  43. Language: C++
  44. Result: Accepted
  45. Time:50 ms
  46. Memory:1916 kb
  47. ****************************************************************/

题目1182:统计单词

题目描述:

编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别输出每个单词含有多少个字符。
(凡是以一个或多个空格隔开的部分就为一个单词)

输入:

输入包括1行字符串,以“.”结束,字符串中包含多个单词,单词之间以一个或多个空格隔开。

输出:

可能有多组测试数据,对于每组数据,
输出字符串中每个单词包含的字母的个数。

样例输入:
hello how are you.
样例输出:
5 3 3 3
  1. #include "stdio.h"
  2. #include "vector"
  3. #include "string"
  4. #include "iostream"
  5. using namespace std;
  6. int main()
  7. {
  8. string str;
  9. while (getline(cin,str))
  10. {
  11. for (size_t i = 0; i < str.length(); i++)
  12. {
  13. int count = 0;
  14. //while (str[i] <= 'z' && str[i] >= 'a' || str[i] <= 'Z' && str[i] >= 'A')
  15. while (isalpha(str[i]))
  16. {//只要是字母就统计
  17. count++;
  18. i++;
  19. }
  20. if (count)//防止多个空格
  21. {
  22. if (i==(str.length()-1))
  23. cout << count;
  24. else
  25. cout << count<<" ";
  26. }
  27. }
  28. cout << endl;
  29. }
  30. return 0;
  31. }
  32. /**************************************************************
  33. Problem: 1182
  34. User: EbowTang
  35. Language: C++
  36. Result: Accepted
  37. Time:20 ms
  38. Memory:1520 kb
  39. ****************************************************************/
#include "stdio.h"
#include "vector"
#include "string"
#include "iostream"
using namespace std;
 
int main()
{
    string str;
    while (getline(cin,str))
    {
        for (size_t i = 0; i < str.length(); i++)
        {
            int count = 0;
            //while (str[i] <= 'z' && str[i] >= 'a' || str[i] <= 'Z' && str[i] >= 'A')
            while (isalpha(str[i]))
            {//只要是字母就统计
                count++;
                i++;
            }
            if (count)//防止多个空格
            {
                if (i==(str.length()-1))
                    cout << count;
                else
                    cout << count<<" ";
            }
        }
        cout << endl;
    }
    return 0;
}
 
/**************************************************************
    Problem: 1182
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:20 ms
    Memory:1520 kb
****************************************************************/


题目1183:守形数

题目描述:

守形数是这样一种整数,它的平方的低位部分等于它本身。
比如25的平方是625,低位部分是25,因此25是一个守形数。
编一个程序,判断N是否为守形数。

输入:

输入包括1个整数N,2<=N<100。

输出:

可能有多组测试数据,对于每组数据,
输出"Yes!”表示N是守形数。
输出"No!”表示N不是守形数。

样例输入:
25
4
样例输出:
Yes!
No!
  1. #include "vector"
  2. #include "string"
  3. #include <iostream>
  4. #include "algorithm"
  5. #include<stdio.h>
  6. using namespace std;
  7. int main()
  8. {
  9. int n, m, f;
  10. while (scanf("%d", &n) != EOF)
  11. {
  12. if(n<2||n>=100)
  13. break;
  14. m = n;
  15. n = n*n;
  16. if (n % 1000 == m)
  17. printf("Yes!\n");
  18. else if (n % 100 == m)
  19. printf("Yes!\n");
  20. else if (n % 10 == m)
  21. printf("Yes!\n");
  22. else
  23. printf("No!\n");
  24. }
  25. return 0;
  26. }
  27. /**************************************************************
  28. Problem: 1183
  29. User: EbowTang
  30. Language: C++
  31. Result: Accepted
  32. Time:0 ms
  33. Memory:1520 kb
  34. ****************************************************************/
#include "vector"
#include "string"
#include <iostream>
#include "algorithm"
#include<stdio.h>
using namespace std;
 
int main()
{
    int n, m, f;
    while (scanf("%d", &n) != EOF)
    {
        if(n<2||n>=100) 
            break;
        m = n;
        n = n*n;
        if (n % 1000 == m)
            printf("Yes!\n");
        else if (n % 100 == m) 
            printf("Yes!\n");
        else if (n % 10 == m)  
            printf("Yes!\n");
        else
            printf("No!\n");
    }
 
    return 0;
}
/**************************************************************
    Problem: 1183
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1520 kb
****************************************************************/


题目1184:二叉树遍历

题目描述:

编一个程序,读入用户输入的一串先序遍历字符串,根据此字符串建立一个二叉树(以指针方式存储)。
例如如下的先序遍历字符串:
ABC##DE#G##F###
其中“#”表示的是空格,空格字符代表空树。建立起此二叉树以后,再对二叉树进行中序遍历,输出遍历结果。

输入:

输入包括1行字符串,长度不超过100。

输出:

可能有多组测试数据,对于每组数据,
输出将输入字符串建立二叉树后中序遍历的序列,每个字符后面都有一个空格。
每个输出结果占一行。

样例输入:
abc##de#g##f###
样例输出:
c b e g d f a 
  1. #include "string"
  2. #include "algorithm"
  3. #include <iostream>
  4. #include "stack"
  5. #include <cmath>
  6. #include <set>
  7. using namespace std;
  8. string preStr;
  9. // 节点定义
  10. class BSTNode
  11. {
  12. public:
  13. BSTNode()// 默认构造
  14. {
  15. pRight = NULL;
  16. pLeft = NULL;
  17. value = 0;
  18. }
  19. ~BSTNode();
  20. friend class LinkBST;// 允许链表类随意访问节点数据
  21. private:
  22. char value;
  23. BSTNode *pRight;
  24. BSTNode *pLeft;
  25. };
  26. // 无头结点的二叉树定义
  27. class LinkBST
  28. {
  29. public:
  30. LinkBST(){};
  31. ~LinkBST(){};
  32. // 根据字符串重建二叉树
  33. void ReBuildTree(BSTNode *&pNode, int &index);
  34. // 中序遍历
  35. void InOrder(BSTNode *&pRoot);
  36. };
  37. // 中序遍历
  38. void LinkBST::InOrder(BSTNode *&pNode)
  39. {
  40. if (pNode != NULL)
  41. {
  42. InOrder(pNode->pLeft);
  43. cout << pNode->value << " ";
  44. InOrder(pNode->pRight);
  45. }
  46. }
  47. // 根据前序字符串重建二叉树
  48. void LinkBST::ReBuildTree(BSTNode *&pNode, int &index)
  49. {
  50. if (index == preStr.size())
  51. return;
  52. if (preStr[index] == '#')
  53. {
  54. pNode = NULL;
  55. index++;
  56. }
  57. else
  58. {
  59. pNode = new BSTNode;
  60. pNode->value = preStr[index];
  61. index++;
  62. ReBuildTree(pNode->pLeft, index);//总是先建完左子树,再建右子树
  63. ReBuildTree(pNode->pRight, index);
  64. }
  65. }
  66. /*
  67. a
  68. / \
  69. b #
  70. / \
  71. c d <------本例题的二叉树逻辑结构
  72. / \ / \
  73. # # e f
  74. / \ / \
  75. # g # #
  76. / \
  77. # #
  78. */
  79. int main()
  80. {
  81. while (cin >> preStr)
  82. {
  83. BSTNode *pRoot = NULL;
  84. LinkBST bst;
  85. int index = 0;
  86. bst.ReBuildTree(pRoot,index);
  87. bst.InOrder(pRoot);
  88. cout << endl;
  89. }
  90. }
#include "string"
#include "algorithm"
#include <iostream>
#include "stack"
#include <cmath>
#include <set>

using namespace std;

string preStr;

// 节点定义
class BSTNode
{
public:
	BSTNode()// 默认构造
	{
		pRight = NULL;
		pLeft = NULL;
		value = 0;
	}
	~BSTNode();
	friend class LinkBST;// 允许链表类随意访问节点数据

private:
	char value;
	BSTNode *pRight;
	BSTNode *pLeft;
};

// 无头结点的二叉树定义 
class LinkBST
{
public:
	LinkBST(){};
	~LinkBST(){};

	// 根据字符串重建二叉树
	void ReBuildTree(BSTNode *&pNode, int &index);

	// 中序遍历
	void InOrder(BSTNode *&pRoot);
	
};

// 中序遍历
void LinkBST::InOrder(BSTNode *&pNode)
{
	if (pNode != NULL)
	{
		InOrder(pNode->pLeft);
		cout << pNode->value << " ";
		InOrder(pNode->pRight);
	}
}

// 根据前序字符串重建二叉树
void LinkBST::ReBuildTree(BSTNode *&pNode, int &index)
{
	if (index == preStr.size())
		return;
	if (preStr[index] == '#')
	{
		pNode = NULL;
		index++;
	}
	else
	{
		pNode = new BSTNode;
		pNode->value = preStr[index];
		index++;
		ReBuildTree(pNode->pLeft, index);//总是先建完左子树,再建右子树
		ReBuildTree(pNode->pRight, index);
	}
}


/*
           a
		  / \
         b   #
		/  \
       c    d        <------本例题的二叉树逻辑结构
	  / \  /  \
     #  # e    f
	     / \  / \
		#   g #  #
		   / \
		  #   #
*/


int main()
{
	while (cin >> preStr)
	{
		BSTNode *pRoot = NULL;
		LinkBST bst;
		int index = 0;
		bst.ReBuildTree(pRoot,index);
		bst.InOrder(pRoot);
		cout << endl;
	}
}



题目1185:特殊排序

题目描述:

输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序。

输入:
输入第一行包括1个整数N,1<=N<=1000,代表输入数据的个数。
接下来的一行有N个整数。
输出:
可能有多组测试数据,对于每组数据,
第一行输出一个整数,代表N个整数中的最大值,并将此值从数组中去除,将剩下的数进行排序。
第二行将排序的结果输出。
样例输入:
4
1 3 4 2
样例输出:
4
1 2 3
提示:

如果数组中只有一个数,当第一行将其输出后,第二行请输出"-1"。

  1. #include "vector"
  2. #include "string"
  3. #include "algorithm"
  4. #include <iostream>
  5. #include "stack"
  6. using namespace std;
  7. int main()
  8. {
  9. int n = 0;
  10. while (cin >> n)
  11. {
  12. vector<int> vec(n);
  13. if (n >= 2)
  14. {
  15. for (int i = 0; i < n; i++)
  16. cin >> vec[i];
  17. sort(vec.begin(), vec.end());
  18. cout << vec[n - 1] << endl;
  19. for (int i = 0; i < n - 2; i++)
  20. cout << vec[i] << " ";
  21. cout << vec[n - 2] << endl;
  22. }
  23. else
  24. {
  25. int val = 0;
  26. cin >> val;
  27. cout << val << endl << -1 << endl;
  28. }
  29. }
  30. }
  31. /**************************************************************
  32. Problem: 1185
  33. User: EbowTang
  34. Language: C++
  35. Result: Accepted
  36. Time:50 ms
  37. Memory:1520 kb
  38. ****************************************************************/
#include "vector"
#include "string"
#include "algorithm"
#include <iostream>
#include "stack"
 
using namespace std;
 
int main()
{
    int n = 0;
    while (cin >> n)
    {
        vector<int> vec(n);
        if (n >= 2)
        {
            for (int i = 0; i < n; i++)
                cin >> vec[i];
            sort(vec.begin(), vec.end());
            cout << vec[n - 1] << endl;
            for (int i = 0; i < n - 2; i++)
                cout << vec[i] << " ";
            cout << vec[n - 2] << endl;
        }
        else
        {
            int val = 0;
            cin >> val;
            cout << val << endl << -1 << endl;
        }
         
    }
}
/**************************************************************
    Problem: 1185
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:50 ms
    Memory:1520 kb
****************************************************************/

题目1187:最小年龄的3个职工

题目描述:

职工有职工号,姓名,年龄.输入n个职工的信息,找出3个年龄最小的职工打印出来。

输入:

输入第一行包括1个整数N,1<=N<=30,代表输入数据的个数。
接下来的N行有N个职工的信息:
包括职工号(整数), 姓名(字符串,长度不超过10), 年龄(1<=age<=100)。

输出:

可能有多组测试数据,对于每组数据,
输出结果行数为N和3的较小值,分别为年龄最小的职工的信息。

关键字顺序:年龄>工号>姓名,从小到大。

样例输入:
5
501 Jack 6
102 Nathon 100
599 Lily 79
923 Lucy 15
814 Mickle 65
样例输出:
501 Jack 6
923 Lucy 15
814 Mickle 65
  1. #include "string"
  2. #include "algorithm"
  3. #include <iostream>
  4. using namespace std;
  5. typedef struct _Worker
  6. {
  7. int num;
  8. string name;
  9. int age;
  10. }Worker;
  11. bool cmpWorker(Worker x, Worker y)
  12. {
  13. if (x.age != y.age)
  14. {
  15. return x.age < y.age;
  16. }
  17. else
  18. {
  19. if (x.num != y.num)
  20. return x.num<y.num;
  21. else
  22. return x.age<y.age;
  23. }
  24. }
  25. int main(void)
  26. {
  27. int n = 0;
  28. while (cin>>n)
  29. {
  30. Worker w[600];
  31. //Worker *w=new Worker[n];
  32. for (size_t i = 0; i < n; i++)
  33. cin >> w[i].num >> w[i].name >> w[i].age;
  34. //多关键字排序
  35. sort(w, w + n, cmpWorker);//功能是先排年龄,若相等则在其基础上对工号和姓名进行排序。
  36. //输出信息
  37. int min = (n>3) ? 3 : n;
  38. for (int i = 0; i < min; i++)
  39. cout << w[i].num << " " << w[i].name << " " << w[i].age << endl;
  40. }
  41. return 0;
  42. }
  43. /**************************************************************
  44. Problem: 1187
  45. User: EbowTang
  46. Language: C++
  47. Result: Accepted
  48. Time:20 ms
  49. Memory:1528 kb
  50. ****************************************************************/
#include "string"
#include "algorithm"
#include <iostream>
 
using namespace std;
 
typedef struct _Worker
{
    int num;
    string name;
    int age;
}Worker;
 
bool cmpWorker(Worker x, Worker y)
{
    if (x.age != y.age)
    {
        return x.age < y.age;
    }
    else
    {
        if (x.num != y.num)
            return x.num<y.num;
        else
            return x.age<y.age;
    }
}
 
int main(void)
{
    int n = 0;
    while (cin>>n)
    {
        Worker w[600];
        //Worker *w=new Worker[n];
        for (size_t i = 0; i < n; i++)
            cin >> w[i].num >> w[i].name >> w[i].age;
        //多关键字排序
        sort(w, w + n, cmpWorker);//功能是先排年龄,若相等则在其基础上对工号和姓名进行排序。
        //输出信息
        int min = (n>3) ? 3 : n;
        for (int i = 0; i < min; i++)
            cout << w[i].num << " " << w[i].name << " " << w[i].age << endl;
    }
         
    return 0;
}
/**************************************************************
    Problem: 1187
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:20 ms
    Memory:1528 kb
****************************************************************/

题目1189:还是约瑟夫环

题目描述:

生成一个长度为21的数组,依次存入1到21;
建立一个长度为21的单向链表,将上述数组中的数字依次存入链表每个结点中;
将上述链表变为单向封闭(循环)链表;从头结点开始数,将第17个结点删除,将它的下一个结点作为新的头结点;
重复上述过程,直到该链表中只剩一个结点,显示该结点中存入的数字。

输入:

没有任何输入数据。

输出:

输出上面题目描述中最后剩下的节点中存入的数字。

样例输入:
 
  
样例输出:
 
  
提示:

请不要直接输出数据水过去,这样达不到提升自己的目的,
请按照题目要求来做题,这样到真正考试时才能应对自如。


  1. #include "iostream"
  2. using namespace std;
  3. //节点定义
  4. class LinkNode
  5. {
  6. public:
  7. LinkNode(int item)//有参数的构造
  8. {//函数参数表中的形参允许有默认值,但是带默认值的参数需要放后面
  9. next = NULL;
  10. data = item;
  11. }
  12. friend class LinkList;//允许链表类随意访问节点数据
  13. private:
  14. int data;
  15. LinkNode *next;
  16. };
  17. // 带头结点的单链表定义
  18. class LinkList
  19. {
  20. public:
  21. //有参数的构造函数
  22. LinkList(int size)
  23. {
  24. head = new LinkNode(0);//头结点,并未该节点赋值0
  25. nLength = 0;
  26. }
  27. ~LinkList(){}
  28. //定位指定的位置,返回该位置上的结点指针
  29. LinkNode* Locate(int pos);
  30. //在指定位置pos插入值为item的结点,失败返回false
  31. bool Insert(int item, int pos);
  32. //创建一个链表环
  33. void CreatCircle();
  34. //数数出局
  35. bool CountMove(int nStep = 0, int nPersons = 0);
  36. private:
  37. LinkNode *head;//头结点指针
  38. int nLength;//统计节点长度,不算头结点
  39. };
  40. //返回链表中第pos个元素的地址,第0个元素是头结点
  41. LinkNode* LinkList::Locate(int pos)
  42. {
  43. LinkNode *p = head;
  44. int i = 0;
  45. while (p != NULL && i < pos)//p==NULL说明是末尾了
  46. {
  47. p = p->next;
  48. i++;
  49. }
  50. return p;
  51. }
  52. //在pos位置的节点后面插入新节点并赋值item
  53. bool LinkList::Insert(int item, int pos)
  54. {
  55. LinkNode *p = Locate(pos);
  56. LinkNode *newNode = new LinkNode(item);//创建新节点,该节点值为item
  57. //建立连接
  58. newNode->next = p->next;
  59. p->next = newNode;
  60. nLength++;
  61. return true;
  62. }
  63. //创建一个链表环 ,将最后一个节点连接第1个节点从而形成环,注意head是第0个节点
  64. void LinkList::CreatCircle()
  65. {
  66. int nEnd = this->nLength;
  67. int nStart = 1;
  68. LinkNode *pTail = Locate(nEnd);
  69. LinkNode *pcirStart = Locate(nStart);
  70. pTail->next = pcirStart;
  71. }
  72. //从npersons个人中,每数到nstep就出局
  73. bool LinkList::CountMove(int nStep, int nPersons)//指定出局人数
  74. {
  75. LinkNode *pCurr = NULL, *pPrev = NULL;
  76. int i = 0,n = 0;//n统计已经出局的人数
  77. pCurr = pPrev = head;
  78. while (n < nPersons)
  79. {
  80. pPrev = pCurr;//这三行代码模拟数数
  81. pCurr = pCurr->next;
  82. i++;
  83. if (i == nStep)// 此时踢出环 ,删除当前节点并且输出该节点的值
  84. {
  85. pPrev->next = pCurr->next;//重新建立连接
  86. delete pCurr;
  87. pCurr = pPrev->next;//指向新位置的下一个节点
  88. i = 1;
  89. n++;
  90. }
  91. if (pPrev == pCurr)//此时最后一个节点
  92. {
  93. cout << pCurr->data << endl;
  94. delete pCurr;
  95. pCurr = NULL;//最后一个节点删除后的“擦屁股”处理
  96. head->next = head;
  97. n++;
  98. break;
  99. }
  100. }
  101. return true;
  102. }
  103. int main()
  104. {
  105. int nPersons = 21,count = 17;
  106. LinkList ysf(nPersons);
  107. for (int i = 0; i < nPersons; i++)
  108. ysf.Insert(i + 1, i);//在第i个位置插入值为i+1的节点
  109. ysf.CreatCircle();
  110. ysf.CountMove(count, nPersons);//数到count出局
  111. return 0;
  112. }
  113. /**************************************************************
  114. Problem: 1189
  115. User: EbowTang
  116. Language: C++
  117. Result: Accepted
  118. Time:0 ms
  119. Memory:1516 kb
  120. ****************************************************************/
#include "iostream"
using namespace std;
 
//节点定义
class LinkNode
{
public:
    LinkNode(int item)//有参数的构造
    {//函数参数表中的形参允许有默认值,但是带默认值的参数需要放后面  
        next = NULL;
        data = item;
    }
    friend class LinkList;//允许链表类随意访问节点数据
 
private:
    int data;
    LinkNode *next;
};
 
// 带头结点的单链表定义 
class LinkList
{
public:
    //有参数的构造函数  
    LinkList(int size)
    {
        head = new LinkNode(0);//头结点,并未该节点赋值0  
        nLength = 0;
    }
    ~LinkList(){}
    //定位指定的位置,返回该位置上的结点指针  
    LinkNode* Locate(int pos);
    //在指定位置pos插入值为item的结点,失败返回false  
    bool Insert(int item, int pos);
    //创建一个链表环  
    void CreatCircle();
    //数数出局  
    bool CountMove(int nStep = 0, int nPersons = 0);
 
private:
    LinkNode *head;//头结点指针
    int nLength;//统计节点长度,不算头结点
};
 
//返回链表中第pos个元素的地址,第0个元素是头结点
LinkNode* LinkList::Locate(int pos)
{
    LinkNode *p = head;
    int i = 0;
    while (p != NULL && i < pos)//p==NULL说明是末尾了
    {
        p = p->next;
        i++;
    }
 
    return p;
}
 
//在pos位置的节点后面插入新节点并赋值item
bool LinkList::Insert(int item, int pos)
{
    LinkNode *p = Locate(pos);
    LinkNode *newNode = new LinkNode(item);//创建新节点,该节点值为item  
    //建立连接
    newNode->next = p->next;
    p->next = newNode;
    nLength++;
    return true;
}
 
//创建一个链表环 ,将最后一个节点连接第1个节点从而形成环,注意head是第0个节点
void LinkList::CreatCircle()
{
    int nEnd = this->nLength;
    int nStart = 1;
    LinkNode *pTail = Locate(nEnd);
    LinkNode *pcirStart = Locate(nStart);
    pTail->next = pcirStart;
}
 
//从npersons个人中,每数到nstep就出局
bool LinkList::CountMove(int nStep, int nPersons)//指定出局人数  
{
    LinkNode *pCurr = NULL, *pPrev = NULL;
    int i = 0,n = 0;//n统计已经出局的人数
    pCurr = pPrev = head;
    while (n < nPersons)
    {
        pPrev = pCurr;//这三行代码模拟数数
        pCurr = pCurr->next;
        i++;
         
        if (i == nStep)// 此时踢出环 ,删除当前节点并且输出该节点的值
        {   
            pPrev->next = pCurr->next;//重新建立连接
            delete pCurr;
            pCurr = pPrev->next;//指向新位置的下一个节点
            i = 1;
            n++;
        }
 
        if (pPrev == pCurr)//此时最后一个节点
        { 
            cout  << pCurr->data << endl;    
            delete pCurr;
            pCurr = NULL;//最后一个节点删除后的“擦屁股”处理  
            head->next = head;
            n++;
            break;
        }
         
    }
    return true;
}
 
int main()
{
    int nPersons = 21,count = 17;
    LinkList ysf(nPersons);
    for (int i = 0; i < nPersons; i++)
        ysf.Insert(i + 1, i);//在第i个位置插入值为i+1的节点
    ysf.CreatCircle();
    ysf.CountMove(count, nPersons);//数到count出局
     
    return 0;
}
/**************************************************************
    Problem: 1189
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1516 kb
****************************************************************/

题目1192:回文字符串

题目描述:

给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。

输入:

输入包括一行字符串,其长度不超过1000。

输出:

可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。

样例输入:
hellolleh
helloworld
样例输出:
Yes!
No!
  1. #include "string"
  2. #include <iostream>
  3. #include "algorithm"
  4. using namespace std;
  5. int main()
  6. {
  7. string str;
  8. while (getline(cin, str))
  9. {
  10. bool flag = false;
  11. for (int i = 0; i < str.length(); i++)
  12. {//回文的重要判断依据就是前后对应位置字符必须一样
  13. if (str[i] != str[str.length() - 1 - i])
  14. {
  15. flag = true;
  16. break;
  17. }
  18. }
  19. if (flag)
  20. cout << "No!" << endl;
  21. else
  22. cout << "Yes!" << endl;
  23. }
  24. return 0;
  25. }
  26. /**************************************************************
  27. Problem: 1192
  28. User: EbowTang
  29. Language: C++
  30. Result: Accepted
  31. Time:40 ms
  32. Memory:1520 kb
  33. ****************************************************************/
#include "string"
#include <iostream>
#include "algorithm"
 
using namespace std;
 
int main()
{
    string str;
    while (getline(cin, str))
    {
        bool flag = false;
        for (int i = 0; i < str.length(); i++)
        {//回文的重要判断依据就是前后对应位置字符必须一样
            if (str[i] != str[str.length() - 1 - i])
            {
                flag = true;
                break;
            }
        }
        if (flag)
            cout << "No!" << endl;
        else
            cout << "Yes!" << endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1192
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:40 ms
    Memory:1520 kb
****************************************************************/

题目1193:矩阵转置

题目描述:

输入一个N*N的矩阵,将其转置后输出。要求:不得使用任何数组(就地逆置)。

输入:

输入的第一行包括一个整数N,(1<=N<=100),代表矩阵的维数。
接下来的N行每行有N个整数,分别代表矩阵的元素。

输出:

可能有多组测试数据,对于每组数据,将输入的矩阵转置后输出。

样例输入:
3
1 2 3
4 5 6
7 8 9
样例输出:
1 4 7
2 5 8
3 6 9
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include "vector"
  4. #include "string"
  5. #include "algorithm"
  6. #include <iostream>
  7. #include "stack"
  8. #include "math.h"
  9. #define MAXN 100
  10. using namespace std;
  11. int main()
  12. {
  13. int n, i, j;
  14. int array[MAXN][MAXN];
  15. while (scanf("%d", &n) != EOF)
  16. {
  17. for (i = 0; i < n; i++)
  18. {//获取数据
  19. for (j = 0; j < n; j++)
  20. scanf("%d", &array[i][j]);
  21. }
  22. for (i = 0; i < n; i++)
  23. {//交换array[i][j]和array[j][i]
  24. for (j = i; j < n; j++)
  25. {
  26. int temp;
  27. temp = array[i][j];
  28. array[i][j] = array[j][i];
  29. array[j][i] = temp;
  30. }
  31. }
  32. for (i = 0; i < n; i++)
  33. {
  34. printf("%d", array[i][0]);
  35. for (j = 1; j < n; j++)
  36. printf(" %d", array[i][j]);
  37. printf("\n");
  38. }
  39. }
  40. return 0;
  41. }
  42. /**************************************************************
  43. Problem: 1193
  44. User: EbowTang
  45. Language: C++
  46. Result: Accepted
  47. Time:10 ms
  48. Memory:1520 kb
  49. ****************************************************************/
#include <cstdio>  
#include <cstdlib>  
#include "vector"
#include "string"
#include "algorithm"
#include <iostream>
#include "stack"
#include "math.h"  
 
#define MAXN 100  
using namespace std;
 
 
int main()
{
    int n, i, j;
    int array[MAXN][MAXN];
    while (scanf("%d", &n) != EOF) 
    {
        for (i = 0; i < n; i++) 
        {//获取数据
            for (j = 0; j < n; j++)
                scanf("%d", &array[i][j]);
        }
        for (i = 0; i < n; i++) 
        {//交换array[i][j]和array[j][i]
            for (j = i; j < n; j++) 
            {
                int temp;
                temp = array[i][j];
                array[i][j] = array[j][i];
                array[j][i] = temp;
            }
        }
        for (i = 0; i < n; i++) 
        {
            printf("%d", array[i][0]);
            for (j = 1; j < n; j++)
                printf(" %d", array[i][j]);
            printf("\n");
        }
    }
    return 0;
}
/**************************************************************
    Problem: 1193
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/

题目1194:八进制

题目描述:

输入一个整数,将其转换成八进制数输出。

输入:

输入包括一个整数N(0<=N<=100000)。

输出:

可能有多组测试数据,对于每组数据,
输出N的八进制表示数。

样例输入:
7
8
9
样例输出:
7
10
11
  1. #include "vector"
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int n = 0;
  7. while (cin >> n )
  8. {
  9. if (n == 0)
  10. {
  11. cout << 0 << endl;
  12. continue;
  13. }
  14. vector<int> vec(100,0);
  15. int nsize = 0;
  16. while (n > 0)
  17. {//获取8进制数,放入数组
  18. vec[nsize++] = n % 8;
  19. n = n / 8;
  20. }
  21. for (int i = nsize-1; i >= 0; i--)
  22. cout << vec[i];
  23. cout << endl;
  24. }
  25. return 0;
  26. }
  27. /**************************************************************
  28. Problem: 1194
  29. User: EbowTang
  30. Language: C++
  31. Result: Accepted
  32. Time:200 ms
  33. Memory:1520 kb
  34. ****************************************************************/
#include "vector"
#include <iostream>
using namespace std;
 
int main()
{
    int n = 0;
    while (cin >> n )
    {
        if (n == 0)
        {
            cout << 0 << endl;
            continue;
        }
        vector<int> vec(100,0);
        int nsize = 0;
        while (n > 0)
        {//获取8进制数,放入数组
            vec[nsize++] = n % 8;
            n = n / 8;
        }
        for (int i = nsize-1; i >= 0; i--)
            cout << vec[i];
        cout << endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1194
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:200 ms
    Memory:1520 kb
****************************************************************/

题目1196:成绩排序

题目描述:

用一维数组存储学号和成绩,然后,按成绩排序输出。

输入:

输入第一行包括一个整数N(1<=N<=100),代表学生的个数。
接下来的N行每行包括两个整数p和q,分别代表每个学生的学号和成绩。

输出:

按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来。
如果学生的成绩相同,则按照学号的大小进行从小到大排序。

样例输入:
3
1 90
2 87
3 92
样例输出:
2 87
1 90
3 92

  1. #include "vector"
  2. #include<algorithm>
  3. #include <iostream>
  4. using namespace std;
  5. typedef struct _StuInfo
  6. {
  7. int num;//学号
  8. int score;//分数
  9. }StuInfo;
  10. bool cmpStu(StuInfo x, StuInfo y)
  11. {
  12. if (x.score != y.score)
  13. return x.score < y.score;
  14. else
  15. {
  16. if (x.num != y.num)//如果分数相同则按照学号排名
  17. return x.num<y.num;
  18. }
  19. }
  20. int main()
  21. {
  22. StuInfo a[100];
  23. int n;
  24. while (cin >> n)//人数
  25. {
  26. //获取数据
  27. for (int i = 0; i<n; i++)
  28. cin >> a[i].num >> a[i].score;
  29. //多关键字排序
  30. sort(a, a + n, cmpStu);//功能是先排分数,若相等则在其基础上对名字和年龄进行排序。
  31. //输出信息
  32. for (int i = 0; i<n; i++)
  33. cout << a[i].num << " " << a[i].score << endl;
  34. }
  35. return 0;
  36. }
  37. /**************************************************************
  38. Problem: 1196
  39. User: EbowTang
  40. Language: C++
  41. Result: Accepted
  42. Time:470 ms
  43. Memory:1520 kb
  44. ****************************************************************/
#include "vector"
#include<algorithm>
#include <iostream>
 
using namespace std;
 
typedef struct _StuInfo
{
    int num;//学号
    int score;//分数
}StuInfo;
 
bool cmpStu(StuInfo x, StuInfo y)
{
    if (x.score != y.score)
        return x.score < y.score;
    else
    {
        if (x.num != y.num)//如果分数相同则按照学号排名
            return x.num<y.num;
    }
}
 
int main()
{
    StuInfo a[100];
    int n;
    while (cin >> n)//人数
    {
        //获取数据
        for (int i = 0; i<n; i++)
            cin >> a[i].num >> a[i].score;
        //多关键字排序
        sort(a, a + n, cmpStu);//功能是先排分数,若相等则在其基础上对名字和年龄进行排序。
        //输出信息
        for (int i = 0; i<n; i++)
            cout << a[i].num << " " << a[i].score << endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1196
    User: EbowTang
    Language: C++
    Result: Accepted
    Time:470 ms
    Memory:1520 kb
****************************************************************/

题目1198:a+b

题目描述:

实现一个加法器,使其能够输出a+b的值。

输入:

输入包括两个数a和b,其中a和b的位数不超过1000位。

输出:

可能有多组测试数据,对于每组数据,
输出a+b的值。

样例输入:
2 6
10000000000000000000 10000000000000000000000000000000
样例输出:
8
10000000000010000000000000000000
  1. #include "vector"
  2. #include "string"
  3. #include <iostream>
  4. #include "algorithm"
  5. #define N 1010
  6. int len = 1001;
  7. using namespace std;
  8. void AddBigNum(const string &a, const string &b, vector<int> &ansStr);
  9. int main()
  10. {
  11. string bigNum1, bigNum2; // 初始状态用string来存储大数
  12. while (cin >> bigNum1 >> bigNum2)
  13. {
  14. int c = max(bigNum1.size(),bigNum2.size());
  15. vector<int> ans(len, 0);//接收答案
  16. AddBigNum(bigNum1, bigNum2, ans);//执行大整数加法
  17. if (ans[0] != 0) //看看最高位是否有进位
  18. for (int i = 0; i <= c; i++)
  19. cout << ans[i];
  20. else
  21. for (int i = 1; i <= c; i++)
  22. cout << ans[i];
  23. cout << endl;
  24. ans.clear();
  25. }
  26. return 0;
  27. }
  28. void AddBigNum(const string &a, const string &b, vector<int> &ans)
  29. {
  30. int length1=a.size(), length2=b.size();
  31. vector<int> anum(len,0),bnum(len,0);
  32. int k = max(a.size(), b.size());
  33. int c = k;
  34. //按照字符串中的数据顺序转换成整数
  35. for (int i = 0; i<length1; k--, i++) //低位放在数组的前面,比如523,a[3]=3,a[2]=2,a[1]=5
  36. anum[k] = a[length1 - 1 - i] - '0';
  37. for (int i = 0, k = c; i<length2; k--, i++) //低位放在数组的前面,比如19,b[3]=9,b[2]=1,b[1]=0
  38. bnum[k] = b[length2 - 1 - i] - '0';
  39. //作位相加
  40. for (int i = c; i>0; i--)
  41. ans[i] = anum[i] + bnum[i];//ans[3]=12,ans[2]=3,ans[1]=5
  42. //进位,低位向高位进位
  43. for (int i = c; i>0; i--)
  44. {
  45. if (ans[i] >= 10)
  46. {//ans[i-1]是高位,ans[i]是低位
  47. ans[i - 1] += ans[i] / 10;
  48. ans[i] = ans[i] % 10;
  49. }
  50. }
  51. }
  52. /**************************************************************
  53. Problem: 1198
  54. User: EbowTang
  55. Language: C++
  56. Result: Accepted
  57. Time:150 ms
  58. Memory:1520 kb
  59. ****************************************************************/  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值