两个典型错误

华为笔试题 :
两个典型错误

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

using namespace std;

const int MaxS = 110;
const int MaxM = pow(10, 5) + 100;
const long long MaxL = pow(10, 6) + 100;


char str[MaxS];
char str2[MaxS];
char *strs[MaxS];
struct Node
{
	char* s;
	int num;
};
Node node[MaxS];

char* tokens1 = "1234567890";
char* tokens2 = "abcdefghijklmnopqrstuvwxyz";

bool cmp(Node a, Node b) {
	if (a.num != b.num) 
		return a.num < b.num;
	int tmp = strcmp(a.s, b.s);
	if (tmp != 0) 
		return tmp < 0;
	return false;
}

void print(int n) {
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < node[i].num;j++) {
			printf("%s",node[i].s);
		}
	}
}

int main()
{
	freopen("Text.txt", "r", stdin);
	while (scanf("%s",str)!= EOF) {
		char * tmp;
		sprintf(str2, str);//error  strtok函数修改了str,但是在64行又对str用strtok,所以错误。这里应该用sprintf()函数对str进行备份。不能用char* str2 = str对str备份,因为str2是个指针,指向了原来的str。
		tmp = strtok(str, tokens1);
		int N = 0;
		node[N++].s = tmp;		
		do {
			tmp = strtok(NULL, tokens1);
			node[N++].s = tmp;
		} while (tmp);
		tmp = strtok(str2, tokens2);
		N = 0;
		node[N++].num = atoi(tmp);
		do {
			tmp = strtok(NULL, tokens2);
			if (tmp == NULL) break;//atoi函数要求它的参数不为空,所以应该加上这一句。应该根据调试出的错误类型推断问题所在。
			node[N++].num = atoi(tmp);
		} while (tmp);
		sort(node, node + N -1,cmp);
		print(N);
	}
    return 0;
}