|  | 
 
| 
题目:老师布置作业,要求计算某年某月某日是这一年的第几天。小莉把日期写成了
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  字符串形式。请帮助小莉编写程序,先将形如“ 2017-03-01 ”的日期字符串
 转换为3个整数,再放入一个整型二维数组中。
 
 例如:
 字符串为 “ 2017-03-01    2016-03-01      2017-12-31 ”,放到整型数组中:
 a[3][3]={2017,3,1,2016,3,1,2017,12,31};
 
 
 
 
复制代码#include <stdio.h>
int main(void) 
{
        char c;
        int a[100][3], temp = 0, *p = a[0], count = 0, i = 0;
        while(~scanf("%c", &c) && c != '\n') {
                if(c != ' ' && c != '-') {
                        temp = temp * 10 + (c - '0');
                } else if(temp != 0) {
                        *(p++) = temp; 
                        count += 1;
                        temp = 0;
                }
        }
        if(temp) {
                *(p++) = temp;
                count += 1;
        }
//        for(i = 0; i < count; i += 3) {
//                printf("%d %d %d\n", *(a[0] + i), *(a[0] + i + 1), *(a[0] + i + 2));
//        }
        return 0;
} 
好久没写纯C的东西了,反正思路这样下来还是挺流畅的,应该不难理解  | 
 |